script fails with return code 0

Advertisement

tperk
Guest

script fails with return code 0

Using WinSCP 4.3.5 (Build 1463) on Windows XP SP3. I'm using the command line version.

WinSCP can falsely detect errors in the call command when the return code is 0. If the return code 0, then there should be no error. This is demonstrated below:

winscp> option echo off
echo            off       
winscp> option bat abort
batch           abort     
winscp> option confirm off
confirm         off       
winscp> option transfer automatic
transfer        automatic 
winscp> open -timeout=1 root:FM@192.168.101.2
Searching for host...
Connecting to host...
Authenticating...
Using username \"root\".
Authenticating with pre-entered password.
Authenticated.
Starting the session...
Reading remote directory...
Session started.
Active session: [1] root@192.168.101.2
winscp> call echo "asdf" >&2
Searching for host...
Connecting to host...
Authenticating...
Using username \"root\".
Authenticating with pre-entered password.
Authenticated.
Starting the session...
Reading remote directory...
Session started.
asdf
Command 'echo "asdf" >&2'
failed with return code 0 and error message
asdf.    

This doesn't happen if I use stdout instead of stderr. So I'm guessing WinSCP is checking stderr when it should only be checking the return code.

Keep up the good work, your software is really useful! Thank you.

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
27,226
Location:
Prague, Czechia

Re: script fails with return code 0

Well, I believe it is perfectly correct to check the error output. And you can always wouraround that the way you did (by redirecting to stardard output).
_________________
Martin Prikryl

Reply with quote

tperk
Guest

I agree that most programs only write to stderr when there is an error, but it is also common practice to write warnings to stderr. So I would argue that proper execution is indicated solely by the exit code.

Also for your consideration: what if you want to test the result of a command?

call if cmd1 ; then cmd2 ; fi    

If cmd1 writes to stderr then the user needs to start putting redirects everywhere.

Maybe I'm being unreasonable, and I should put stuff like this in a bash script instead of writing one-liners. I was just expecting "option batch abort" to be analogous to "set -e".

Anyway, thank you Martin.

Reply with quote

Advertisement

You can post new topics in this forum