Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove setting of CreateNoWindow to reduce overhead #142

Merged
merged 8 commits into from
Mar 14, 2022
11 changes: 9 additions & 2 deletions CliWrap/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,17 @@ private ProcessStartInfo GetStartInfo()
RedirectStandardInput = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true
UseShellExecute = false
};

// Setting CreateNoWindow has a 30ms overhead added to execution time of the process.
// A window won't be created for console applications even when CreateNoWindow = false,
// so it's only necessary to set it if there is no console.
// This check is only necessary on Windows platforms because CreateNoWindow does not work on MacOS or Linux.
// https://github.com/Tyrrrz/CliWrap/pull/142
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && NativeMethods.GetConsoleWindow() == IntPtr.Zero)
startInfo.CreateNoWindow = true;

// Domain and password are only supported on Windows
if (Credentials.Domain is not null || Credentials.Password is not null)
{
Expand Down
10 changes: 10 additions & 0 deletions CliWrap/Utils/NativeMethods.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
using System.Runtime.InteropServices;

namespace CliWrap.Utils;

internal static class NativeMethods
{
[DllImport("kernel32.dll")]
public static extern IntPtr GetConsoleWindow();
}