Error in "call" does not abort the script

Advertisement

ZS
Guest

Error in "call" does not abort the script

Hi,

I'm using a script to upload a zip file, unzip it, and delete the zip file - all through an SFTP connection.

I noticed that the script does not abort if the call to the unzip command fails.

I would expect that the script below would abort because of the "call false" and will never execute the "call echo ..." command.

open some_sftp_site.org
call false
call echo WinSCP did not abort
exit
However, the script continues regardless of the failure of the first "call" command.

From the log file, it is clear that WinSCP.com recieves the error status of the failing "call":
< 2015-08-04 07:27:06.066 Script: Session started.
. 2015-08-04 07:27:06.067 Executing user defined command on command session.
> 2015-08-04 07:27:06.067 [Shell] false ; echo "WinSCP: this is end-of-file:$?"
< 2015-08-04 07:27:06.138 [Shell] WinSCP: this is end-of-file:1
> 2015-08-04 07:27:06.138 [Shell] pwd ; echo "WinSCP: this is end-of-file:$?"
< 2015-08-04 07:27:06.210 [Shell] /home/osm
< 2015-08-04 07:27:06.210 [Shell] WinSCP: this is end-of-file:0
. 2015-08-04 07:27:06.210 Cached directory change via "/home/osm" to "/home/osm".
. 2015-08-04 07:27:06.210 Getting current directory name.
. 2015-08-04 07:27:06.210 Getting current directory name.
> 2015-08-04 07:27:06.211 Script: call echo WinSCP did not abort
. 2015-08-04 07:27:06.211 Executing user defined command on command session.
> 2015-08-04 07:27:06.211 [Shell] echo WinSCP did not abort ; echo "WinSCP: this is end-of-file:$?"
< 2015-08-04 07:27:06.283 Script: WinSCP did not abort
< 2015-08-04 07:27:06.283 [Shell] WinSCP did not abort
< 2015-08-04 07:27:06.283 [Shell] WinSCP: this is end-of-file:0
Is there a way to abort the script after a call fails?

Thanks!

Reply with quote

Advertisement

SZ
Guest

Re: Error in "call" does not abort the script

The script contained "option batch abort":
option batch abort
open some_sftp_site.org 
call false
call echo WinSCP did not abort
exit

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
40,476
Location:
Prague, Czechia

Re: Error in "call" does not abort the script

WinSCP is rather tolerant to exit code 1 as many commands return is just as a warning. Use some if condition to turn 1 to 2.

Reply with quote

Guest

I've been working with Unix and Linux for years, and I'm not aware of such an interpretation of exit status 1 as a warning. It is also not in line, for example, with the BASH Exit Codes (<invalid hyperlink removed by admin>) documentation. See "Are there any standard exit status codes in Linux?" on StackOverflow for an extended discussion.

Morever, transforming exit status 1 to 2 in the remote machine is not very simple, and may depend on the login shell of the specific remote host.

Given the above, please reconsider the current behavior of WinSCP or provide a way set WinSCP to treat exit code 1 as a failure.

Thanks in advance!

Reply with quote

Advertisement

You can post new topics in this forum