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
12 changes: 10 additions & 2 deletions CliWrap/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ namespace CliWrap;
/// </summary>
public partial class Command : ICommandConfiguration
{
[DllImport("kernel32.dll")]
private static extern IntPtr GetConsoleWindow();
Tyrrrz marked this conversation as resolved.
Show resolved Hide resolved

/// <inheritdoc />
public string TargetFilePath { get; }

Expand Down Expand Up @@ -331,10 +334,15 @@ 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.
if (GetConsoleWindow() == IntPtr.Zero)
startInfo.CreateNoWindow = true;
Tyrrrz marked this conversation as resolved.
Show resolved Hide resolved

// Domain and password are only supported on Windows
if (Credentials.Domain is not null || Credentials.Password is not null)
{
Expand Down