Topic "script fails with return code 0"

Author Message
tperk

Guest


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:

Code:
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.
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24994
Location: Prague, Czechia
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
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?

Code:

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.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24994
Location: Prague, Czechia
This issue has been added to the tracker:
https://winscp.net/tracker/show_bug.cgi?id=749
_________________
Martin Prikryl
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License