Skip to content

Commit 34c9c6d

Browse files
committed
fix: use single quotes for PowerShell commands to preserve variables on Linux
1 parent 6dcdaf1 commit 34c9c6d

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/integrations/terminal/__tests__/streamUtils/pwshStream.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,24 @@ export function createPowerShellStream(command: string): CommandStream {
1313

1414
try {
1515
// Execute the PowerShell command directly
16-
// Wrap the command in double quotes to preserve it when passing to pwsh
17-
const shellCommand = `pwsh -NoProfile -NonInteractive -Command "${command.replace(/"/g, '\\"')}"`
16+
// Use single quotes for the Command parameter to preserve PowerShell variables
17+
// Escape any single quotes in the command
18+
const escapedCommand = command.replace(/'/g, "'\\''")
19+
const shellCommand = `pwsh -NoProfile -NonInteractive -Command '${escapedCommand}'`
1820

1921
realOutput = execSync(shellCommand, {
2022
encoding: "utf8",
2123
maxBuffer: 100 * 1024 * 1024,
22-
stdio: ["pipe", "pipe", "ignore"], // Redirect stderr to null
24+
stdio: ["pipe", "pipe", "pipe"], // Capture stderr for debugging
2325
})
2426
exitCode = 0 // Command succeeded
2527
} catch (error: any) {
2628
// Command failed - get output and exit code from error
2729
realOutput = error.stdout?.toString() || ""
30+
console.error(`PowerShell command failed with status ${error.status || "unknown"}:`, error.message)
31+
if (error.stderr) {
32+
console.error(`stderr: ${error.stderr.toString()}`)
33+
}
2834
exitCode = error.status || 1
2935
}
3036

0 commit comments

Comments
 (0)