ssh -i private_linux_key user@machine "exit 1" || echo %errorlevel%
This always prints 0
. How can I get actual error code returned by ssh?
||
somehow detects that there was an error.
I've found a solution, thanks to following question: https://stackoverflow.com/questions/11554324/batch-file-errorlevel-issue
setlocal enabledelayedexpansion
ssh -i private_linux_key user@machine "exit 1" || echo !errorlevel!
Or even simplier
ssh -i private_linux_key user@machine "exit 1"
exit %ERRORLEVEL%
The latter is possible only when there are no more additional script lines after exit
, of course
To read more about enabledelayedexpansion
and windows/unix shells differences: http://blogs.msdn.com/b/oldnewthing/archive/2006/08/23/714650.aspx
ssh
exited cleanly, so the return value is0
.;echo $?
to your command, but that won't set theerrorlevel
variable :\