Skip to content

Commit dcc7f77

Browse files
committed
🤖 fix: use bash -c instead of stdin piping to capture WSL output
When using 'echo $s | wsl bash', the output from bash wasn't being captured by PowerShell. Change to 'wsl bash -c $s' which passes the script as an argument and properly captures stdout/stderr.
1 parent accb21f commit dcc7f77

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/node/utils/main/bashPath.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -390,15 +390,18 @@ export function getSpawnConfig(runtime: BashRuntime, script: string, cwd?: strin
390390
const psPath = getPowerShellPath();
391391
if (psPath) {
392392
// Base64 encode the script to avoid any PowerShell parsing issues
393-
// PowerShell will decode it and pipe to WSL bash
393+
// PowerShell will decode it and pass to WSL bash -c
394394
const base64Script = Buffer.from(fullScript, "utf8").toString("base64");
395395

396396
// Build the PowerShell command that:
397-
// 1. Decodes the base64 script
398-
// 2. Pipes it to WSL bash via echo
397+
// 1. Decodes the base64 script into variable $s
398+
// 2. Passes $s to WSL bash -c (not stdin piping - that loses output)
399399
const wslArgs = runtime.distro ? `-d ${runtime.distro}` : "";
400-
const psCommand = `$s=[System.Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('${base64Script}'));` +
401-
`echo $s | wsl ${wslArgs} bash`.trim();
400+
// Use Invoke-Expression to run the wsl command with the decoded script
401+
// This ensures stdout/stderr are properly captured
402+
const psCommand =
403+
`$s=[System.Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('${base64Script}'));` +
404+
`wsl ${wslArgs} bash -c $s`.trim();
402405

403406
return {
404407
command: psPath,

0 commit comments

Comments
 (0)