Get return code of "call"

Advertisement

Clem
Joined:
Posts:
2

Get return code of "call"

Hi,

I'm using WinSCP.com and I'm trying to get the return code of commands called with call
Basically, I launch the following command
WinSCP.com /script=./script.txt /parameter 'foo' 'bar'
With the script file which looks like
open scp://root:strongPassword@1.2.3.4 -hostkey=*
call /root/myRemoteScript.sh %1% %2%
close
exit
But even if /root/myRemoteScript.sh %1% %2% returns 1, WinSCP.com returns 0. I grabbed the return code of WinSCP.com with %ERRORLEVEL%

How can I do that?

Thank you!

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,378
Location:
Prague, Czechia

Re: Get return code of "call"

WinSCP returns exit code 1 (by default), when the command returns exit code >= 2. You can make WinSCP return 1 even if the command returns 1, by setting ExitCode1IsError raw session setting:
open scp://root:strongPassword@1.2.3.4 -hostkey=* -rawsetting ExitCode1IsError=1
But you cannot make WinSCP return the actual exit code of the command.
WinSCP is not the right tool for automating remote shell command execution.
Use Plink instead.

Btw, combination of "strongPassword" and -hostkey=* is just wrong. You are possibly sending your "strong password" right to the hands of an attacker.

Reply with quote

Advertisement

You can post new topics in this forum