Skip to content

Commit

Permalink
Remove setting of CreateNoWindow to reduce overhead (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-g-holm-intel authored Mar 14, 2022
1 parent 3639973 commit c55bba6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
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();
}

0 comments on commit c55bba6

Please sign in to comment.