Skip to content

Commit b33bd6a

Browse files
myfuncsteipete
authored andcommitted
fix(bash): use PowerShell on Windows to capture system utility output
Windows system utilities like ipconfig, systeminfo, etc. write directly to the console via WriteConsole API instead of stdout. When Node.js spawns cmd.exe with piped stdio, these utilities produce empty output. Changes: - Switch from cmd.exe to PowerShell on Windows (properly redirects output) - Disable detached mode on Windows (PowerShell doesn't pipe stdout when detached) - Add windowsHide option to prevent console window flashing - Update tests to use PowerShell-compatible syntax (Start-Sleep, semicolons)
1 parent e3be5f8 commit b33bd6a

3 files changed

Lines changed: 19 additions & 9 deletions

File tree

src/agents/bash-tools.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ import {
99
import { sanitizeBinaryOutput } from "./shell-utils.js";
1010

1111
const isWin = process.platform === "win32";
12-
const shortDelayCmd = isWin ? "ping -n 2 127.0.0.1 > nul" : "sleep 0.05";
13-
const yieldDelayCmd = isWin ? "ping -n 3 127.0.0.1 > nul" : "sleep 0.2";
14-
const longDelayCmd = isWin ? "ping -n 4 127.0.0.1 > nul" : "sleep 2";
15-
const joinCommands = (commands: string[]) =>
16-
commands.join(isWin ? " & " : "; ");
12+
// PowerShell: Start-Sleep for delays, ; for command separation, $null for null device
13+
const shortDelayCmd = isWin ? "Start-Sleep -Milliseconds 50" : "sleep 0.05";
14+
const yieldDelayCmd = isWin ? "Start-Sleep -Milliseconds 200" : "sleep 0.2";
15+
const longDelayCmd = isWin ? "Start-Sleep -Seconds 2" : "sleep 2";
16+
// Both PowerShell and bash use ; for command separation
17+
const joinCommands = (commands: string[]) => commands.join("; ");
1718
const echoAfterDelay = (message: string) =>
1819
joinCommands([shortDelayCmd, `echo ${message}`]);
1920
const echoLines = (lines: string[]) =>

src/agents/bash-tools.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,15 +265,17 @@ export function createBashTool(
265265
{
266266
cwd: workdir,
267267
env: process.env,
268-
detached: true,
268+
detached: process.platform !== "win32",
269269
stdio: ["pipe", "pipe", "pipe"],
270+
windowsHide: true,
270271
},
271272
)
272273
: spawn(shell, [...shellArgs, params.command], {
273274
cwd: workdir,
274275
env,
275-
detached: true,
276+
detached: process.platform !== "win32",
276277
stdio: ["pipe", "pipe", "pipe"],
278+
windowsHide: true,
277279
});
278280

279281
const session = {

src/agents/shell-utils.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@ import { spawn } from "node:child_process";
22

33
export function getShellConfig(): { shell: string; args: string[] } {
44
if (process.platform === "win32") {
5-
const shell = process.env.COMSPEC?.trim() || "cmd.exe";
6-
return { shell, args: ["/d", "/s", "/c"] };
5+
// Use PowerShell instead of cmd.exe on Windows.
6+
// Problem: Many Windows system utilities (ipconfig, systeminfo, etc.) write
7+
// directly to the console via WriteConsole API, bypassing stdout pipes.
8+
// When Node.js spawns cmd.exe with piped stdio, these utilities produce no output.
9+
// PowerShell properly captures and redirects their output to stdout.
10+
return {
11+
shell: "powershell.exe",
12+
args: ["-NoProfile", "-NonInteractive", "-Command"],
13+
};
714
}
815

916
const shell = process.env.SHELL?.trim() || "sh";

0 commit comments

Comments
 (0)