Skip to content

Commit 42b599d

Browse files
adityapatwardhanAndrew
authored andcommitted
Fix global tool issues around exit code, command line parameters and path with spaces (PowerShell#10461)
1 parent ff29282 commit 42b599d

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/Microsoft.PowerShell.GlobalTool.Shim/GlobalToolShim.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ public class EntryPoint
2121
/// <summary>
2222
/// Entry point for the global tool.
2323
/// </summary>
24-
/// <param name="args">Arguments passed to the global tool.</param>
25-
public static void Main(string[] args)
24+
/// <param name="args">Arguments passed to the global tool.</param>'
25+
/// <returns>Exit code returned by pwsh.</returns>
26+
public static int Main(string[] args)
2627
{
2728
var currentPath = new FileInfo(System.Reflection.Assembly.GetEntryAssembly().Location).Directory.FullName;
2829
var isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
@@ -31,11 +32,13 @@ public static void Main(string[] args)
3132

3233
string argsString = args.Length > 0 ? string.Join(" ", args) : null;
3334
var pwshPath = Path.Combine(currentPath, platformFolder, PwshDllName);
34-
string processArgs = string.IsNullOrEmpty(argsString) ? $"{pwshPath}" : $"{pwshPath} -c {argsString}";
35+
string processArgs = string.IsNullOrEmpty(argsString) ? $"\"{pwshPath}\"" : $"\"{pwshPath}\" {argsString}";
3536

3637
if (File.Exists(pwshPath))
3738
{
38-
System.Diagnostics.Process.Start("dotnet", processArgs).WaitForExit();
39+
var process = System.Diagnostics.Process.Start("dotnet", processArgs);
40+
process.WaitForExit();
41+
return process.ExitCode;
3942
}
4043
else
4144
{

0 commit comments

Comments
 (0)