Skip to content

Report real exit codes for Windows targets#125

Merged
freekmurze merged 1 commit into
mainfrom
fix/windows-target-exit-codes
Jul 24, 2026
Merged

Report real exit codes for Windows targets#125
freekmurze merged 1 commit into
mainfrom
fix/windows-target-exit-codes

Conversation

@freekmurze

Copy link
Copy Markdown
Member

Fixes #124.

On a Windows target, isSuccessful() always returned true and getExitCode() always 0, even for failing commands. The package pipes commands to the remote shell through a heredoc, which relies on bash -se to propagate a failure. On Windows the remote shell is cmd.exe, which reads stdin differently, prints its banner/prompt into the output, and exits 0 regardless of what failed.

This adds an onWindows() method that passes the commands as an argument to ssh instead. Windows OpenSSH then runs them through cmd.exe /c, so the real exit code is preserved and the prompt noise is gone.

Ssh::create('user', 'host')->onWindows()->execute('dir');

Add an onWindows() method that passes commands as an ssh argument instead
of piping them to the remote shell via a heredoc. On Windows the remote
shell is cmd.exe, which reads stdin differently and always exits 0, so
isSuccessful() and getExitCode() never reflected a failed command. Passing
the command as an argument runs it through cmd.exe /c, preserving the real
exit code.
@freekmurze
freekmurze merged commit 3335ab1 into main Jul 24, 2026
17 checks passed
@freekmurze
freekmurze deleted the fix/windows-target-exit-codes branch July 24, 2026 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Failed commands always appear to return successful statuses on Windows targets

1 participant