Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have two different servers (A and B, both are Windows) and I am executing putty via command line between them. Server A executes remotely an script in server B and everything works fine, but I am not able to get the output (ERRORLEVEL) in server A once the script has been executed in server B. I mean, I can get the output but always says that the process has finished successfully even if the process in server B has failed.

I attach an small example of the process (ExProcess.bat) I have in server B:

set LOG_PATH=C:\Project\Logs
set BIN_PATH=C:\Project\bin

echo %date% %time% >> %LOG_PATH%\logfile.txt
if not %ERRORLEVEL%==0 exit %ERRORLEVEL% 

And this is how I am making the remote call from server A:

putty -ssh server02 -P 22 -l user1 -pw password1 -m C:\Project\SSH_PRG0001_CMPG0001.txt

SSH_PRG0001_CMPG0001.txt contains the remote batch (C:\ExProcess.bat)

If I execute in Windows Command line %ERRORLEVEL% once I have executed the putty command I am not getting the correct output of the process I have run remotely.

I have checked that the remote process is returning the correct output error in server B, but my problem is that I cannot get this output from server A.

Thanks for your help

share|improve this question

As you're discovering, this won't work.

%ERRORLEVEL% (which is not, in fact, "output", but rather a function of the local shell) returns the status of the last command executed; on server B, that's EXECUTE_MY_COMMAND, as you want it to be -- but on A, it's instead putty! Since Putty successfully connected and did its thing, %ERRORLEVEL% is 0, as it should be.

You could modify your script on B to end with something like echo %ERRORLEVEL% (instead of your if statement), then capture that output on A (e.g. via redirection) and react accordingly. Or, whatever it is on A that's responding to the result, you could consider reacting on B instead, making the entire process entirely self-contained on server B and merely triggered by the connection from A.

share|improve this answer
Thanks for your response. I have added "echo" at the end of the script instead of using the IF statement, but when I try to redirect the output to a flat file it doesn't write anything. For example: putty -ssh server02 -P 22 -l user1 -pw password1 -m C:\Project\SSH_PRG0001_CMPG0001.txt > C:\file.txt Thanks – Jesus Mar 25 '14 at 20:04
When you run it without the redirection, do you see the expected output? – Kromey Mar 25 '14 at 20:12
I see that the process fails and it writes 1 (echo 1 when fails), but I cannot get this error from the server that is making the remote call – Jesus Mar 25 '14 at 23:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.