Skip to content

Commit 97369cc

Browse files
committed
wslutils: guard against failure to launch pwsh
Let's not crash the process if we are unable to launch PowerShell to determine the Windows session ID. Signed-off-by: Matthew John Cheetham <mjcheetham@outlook.com>
1 parent d31f62c commit 97369cc

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)