From ef2ba40ca7f60782de12b50394c0833bdb8789d3 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Wed, 6 Jul 2016 15:00:23 -0700 Subject: [PATCH] Use start in Invoke-Item to open items on Windows Since `UseShellExecute` cannot be used. --- .../namespaces/FileSystemProvider.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/System.Management.Automation/namespaces/FileSystemProvider.cs b/src/System.Management.Automation/namespaces/FileSystemProvider.cs index 2c83a4ea18..7ee00beb27 100644 --- a/src/System.Management.Automation/namespaces/FileSystemProvider.cs +++ b/src/System.Management.Automation/namespaces/FileSystemProvider.cs @@ -1333,14 +1333,18 @@ namespace Microsoft.PowerShell.Commands { System.Diagnostics.Process invokeProcess = new System.Diagnostics.Process(); + invokeProcess.StartInfo.UseShellExecute = false; + if (Platform.IsWindows) { - System.Diagnostics.Process.Start(path); - } + invokeProcess.StartInfo.FileName = "cmd.exe"; + // start is very picky: the "optional" TITLE as the first argument should always be included, otherwise it can silently fail + invokeProcess.StartInfo.Arguments = string.Format(@"/c ""start /b """" ""{0}""""", path); + } else if (Platform.IsOSX) { invokeProcess.StartInfo.FileName = "open"; invokeProcess.StartInfo.Arguments = path; - } + } else if (Platform.IsLinux) { invokeProcess.StartInfo.FileName = "xdg-open"; invokeProcess.StartInfo.Arguments = path;