Skip to content

Commit e3790f6

Browse files
committed
Fix: Apply suggestions from copilot
1 parent 520c651 commit e3790f6

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

Source/NETworkManager/ViewModels/PowerShellHostViewModel.cs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -577,8 +577,12 @@ private void TryFindExecutable()
577577
if (realPwshPath != null)
578578
applicationFilePath = realPwshPath;
579579
}
580-
else if (string.IsNullOrEmpty(applicationFilePath))
580+
581+
// Fallback to Windows PowerShell
582+
if (string.IsNullOrEmpty(applicationFilePath))
581583
{
584+
Log.Warn("Failed to resolve pwsh.exe path. Falling back to Windows PowerShell.");
585+
582586
applicationFilePath = ApplicationHelper.Find(PowerShell.WindowsPowerShellFileName);
583587
}
584588

@@ -624,7 +628,13 @@ private string FindRealPwshPath(string path)
624628

625629
string output = process.StandardOutput.ReadToEnd();
626630

627-
process.WaitForExit();
631+
if(!process.WaitForExit(10000))
632+
{
633+
process.Kill();
634+
Log.Warn("Timeout while trying to resolve real pwsh path.");
635+
636+
return null;
637+
}
628638

629639
if (string.IsNullOrEmpty(output))
630640
return null;
@@ -634,13 +644,14 @@ private string FindRealPwshPath(string path)
634644
.Replace(@"\n", string.Empty)
635645
.Replace("\r\n", string.Empty)
636646
.Replace("\n", string.Empty)
637-
.Replace("\r", string.Empty)
638-
.Trim();
647+
.Replace("\r", string.Empty);
639648

640-
return output;
649+
return output.Trim();
641650
}
642-
catch
651+
catch (Exception ex)
643652
{
653+
Log.Error($"Failed to resolve real pwsh path: {ex.Message}");
654+
644655
return null;
645656
}
646657
}

0 commit comments

Comments
 (0)