Skip to content

Commit 1d07064

Browse files
authored
Guard against failure to launch PowerShell from WSL (#2256)
Let's not crash the process if we are unable to launch PowerShell to determine the Windows session ID.
2 parents 2727c9c + 97369cc commit 1d07064

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/shared/Core/WslUtils.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,16 @@ public static int GetWindowsSessionId(IFileSystem fs)
195195
const string script = @"(Get-Process -ID $PID).SessionId";
196196
using (Process proc = CreateWindowsShellProcess(fs, WindowsShell.PowerShell, script))
197197
{
198-
proc.Start();
199-
proc.WaitForExit();
198+
try
199+
{
200+
proc.Start();
201+
proc.WaitForExit();
202+
}
203+
catch
204+
{
205+
// Unable to start the process, return unknown session ID
206+
return -1;
207+
}
200208

201209
if (proc.ExitCode == 0)
202210
{

0 commit comments

Comments
 (0)