rsh command exit code

Microsoft Windows xp professional w/serv...
May 4, 2010 at 09:12:05
Specs: Windows XP, 4GB

I'm newbie to windows batch scripting.

I have 2 files inside.bat & outside.bat.

Inside.bat code:
EXIT /B 16

Outside.bat code:
rsh my_machine -lmy_user "C:\\myfolder\\inside.bat"

When I run outside.bat, RETURNSTAT is returning rsh exit code. how to get the return code of inside.bat, which is 16 when I execute outside.bat

See More: rsh command exit code

Report •

May 4, 2010 at 09:42:23
I'm guessing:

Inside.bat code:
set /a R=16

Outside.bat code:
rsh my_machine -lmy_user "C:\\myfolder\\inside.bat"
echo R is %R%

Helping others achieve escape felicity


Report •

May 4, 2010 at 09:52:45
Mechanix2Go: I'm guessing:
Wouldn't work; RSH runs the supplied command on a different server, and different server = different environment. (This is also the problem with getting the ErrorLevel.)

I think PSEXEC will quit with the remote's ErrorLevel, but I can't test it ATM.

Report •

May 4, 2010 at 11:52:02
Thanks for replying..

Mechanix2Go: it didnot work. R is not returning anything.

Razor2.3: I don't have PSEXEC executable in my server/PC. How to get it?

Report •

Related Solutions

May 4, 2010 at 14:19:40

Report •

May 4, 2010 at 15:34:09
or you can always communicate by squib-file if you have write-access to network drive:
> Z:\work\tmp echo 16

Report •

May 5, 2010 at 02:44:17
Can be solved in different manners:

1. catch and act on the errorlevel inside the "inside.bat" itself. Maybe it's not possible, maybe it is ... You can handle errorcodes inside scripts, without any issue, you don't need to pass them through a called script.

2. Write a file somewhere, indicating the result. Now, since this involves remote computers, it's more difficult, but know that the filesystem is often used as an alternative "communication layer", since it is common inside one OS (but here, different computers I acknowledge. ... still, shared filesystem) ?

3. Try using variables, don't use "setlocal". Possibly RSH will typically destroy all variables, but you can try.

Report •

May 6, 2010 at 06:36:58
Thanks again for your replies.. I can't find the fix yet..

1) I should capture error at outside.bat only.
2)I cannot use the technique of writing to temporary network file. Because, outside.bat script will be called 10+ times at the same time.
3) I'm not using setlocal anywhere. So, all variables are global.

Report •

May 7, 2010 at 12:37:53
Here is the fix that's working for me.

Inside.bat :
echo DELIM16
EXIT /B 16

Outside.bat file:
FOR /F "usebackq tokens=1 delims=DELIM" %%A IN (`cmd /q/c rsh my_machine -lmy_user C:\my_folder\inside.bat`) DO set var1=%%A
echo exit status is %var1%
EXIT /B %var1%

Report •

May 9, 2010 at 09:30:15
Nice, I like that. Good one !

Report •

May 9, 2010 at 18:59:24
Yeah, I tested it. PSEXEC will exit with whatever errorlevel the remotely executed program returns. (NOTE: It also returns its own errorlevel if something goes amiss when starting the remote app.)
Y:\WINDOWS\others>psexec \\raz cmd /c exit 16

PsExec v1.72 - Execute processes remotely
Copyright (C) 2001-2006 Mark Russinovich
Sysinternals -

cmd exited on raz with error code 16.

Y:\WINDOWS\others>echo %errorlevel%


Report •

Ask Question