豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

start_process captures no stdout from external executables when defaultShell is pwsh.exe #378

@JesperLive

Description

@JesperLive

GitHub Issue Draft: DesktopCommanderMCP pwsh stdout

Repo: wonderwhy-er/DesktopCommanderMCP
Title: start_process captures no stdout from external executables when defaultShell is pwsh.exe


Description

When defaultShell is set to pwsh.exe (PowerShell 7.5.4), start_process
captures zero stdout lines from any external executable (python, git, node,
etc.). The process exits with code 0 but all output is lost. Only pwsh-native
commands (Write-Output, echo) produce captured output.

Switching back to powershell.exe (5.1) immediately restores stdout capture
for all external executables.

Environment

  • DC version: 0.2.38 (DXT/Electron)
  • OS: Windows 11
  • Node.js: 25.7.0
  • pwsh: 7.5.4 (.NET 8)
  • powershell.exe: 5.1.x
  • Python: 3.14.3
  • Git: 2.53.0

Steps to Reproduce

  1. set_config_value defaultShell to pwsh.exe
  2. start_process with python -c "print('hello')"
  3. Observe: PID assigned, (shell: pwsh.exe) shown, but Initial output is empty
  4. read_process_output: 0 lines, exit code 0
  5. set_config_value defaultShell back to powershell.exe
  6. Same command: output captured normally

Test Matrix

Command defaultShell Captured?
echo "test" (native) pwsh.exe YES
Write-Output "test" pwsh.exe YES
python -c "print('hello')" pwsh.exe NO - 0 lines, exit 0
& python -c "print('hello')" pwsh.exe NO - 0 lines, exit 0
git --version pwsh.exe NO - 0 lines, exit 0
python -c "import sys; print('hello'); sys.stdout.flush()" pwsh.exe NO
$out = python -c "print('hello')"; Write-Output $out pwsh.exe NO
python -c "print('hello')" powershell.exe YES
git --version powershell.exe YES

Key observation: A visible python.exe console window appears on the
desktop during pwsh tests, suggesting stdout is routed to a detached console
rather than DC's capture pipe.

Patches Attempted

Patch 1: Remove -Login flag

getShellSpawnArgs() uses ['-Login', '-Command', command] for pwsh.
Removed -Login so args become ['-Command', command].
Result: No fix. External exe stdout still not captured.

Patch 2: shell option + explicit stdio

Changed from spawn('pwsh.exe', ['-Command', cmd]) to
spawn(cmd, [], { shell: 'pwsh.exe', stdio: ['pipe','pipe','pipe'] }).
Result: npx cache regenerated on restart, wiping patch. Even if preserved,
the architectural issue likely remains.

Analysis

The issue appears to be in how Node.js child_process.spawn() handles stdio
inheritance differently for pwsh.exe vs powershell.exe:

  • powershell.exe (native Windows console host): Child processes inherit
    DC's stdio pipes correctly. stdout flows back through Node.js to DC.
  • pwsh.exe (.NET 8 app): Child processes appear to get a new console
    allocation instead of inheriting pipes. stdout goes to the visible console
    window, not back to DC.

This may relate to:

  • .NET 8 runtime allocating its own console via AllocConsole()
  • Differences in how CreateProcess handles STARTUPINFO for .NET vs native
    executables
  • Node.js spawn not setting CREATE_NO_WINDOW or DETACHED_PROCESS flags
    appropriately for .NET-based shells

Workaround

Using powershell.exe (5.1) as defaultShell. This has its own issues
(UTF-8 BOM injection in pipes, UTF-16LE encoding in redirects) but stdout
capture works reliably for all external executables.

Suggested Fix

The getShellSpawnArgs() function in terminal-manager.js may need
platform-specific spawn options for pwsh.exe on Windows, such as:

  • Explicit windowsHide: true in spawn options
  • CREATE_NO_WINDOW process creation flag
  • Different stdio configuration for .NET-based shells

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions