Errorlevel not as expected

Advertisement

MajorTom2004
Joined:
Posts:
7
Location:
Switzerland

Errorlevel not as expected

Hello.

I use the WinSCP.com version 4.4.0, and there I found a behaviour, which is not transparent to me.
I test this version since I have the exact documented problem in Bug #953 in Version 4.3.2.

Here is what I do:

C:\temp> E:\FTP_Tools\WinSCP\WinSCP.com /console "PROFILE_NAME"
winscp> option batch abort
winscp> option confirm off
winscp> option transfer ASCII
winscp> cd /
winscp> get filename_exist.csv
winscp> close
winscp> exit
C:\temp> echo %errorlevel%
0
C:\temp>

This means, the session is opened correctly, the file is found and downloaded and WinSCP.com returns an errorlevel of "0"
Now, the "get line" is changed to "get filename_does_not_exist.csv", after finsishing the winscp executable, the errorlevel returned is "1".
This is exactly, what I expect, success returns a "0", error returns a "1".

In the next step, I write all the commands into a file called E:\FTP_Scripts\0099_wscp.scri instead of supplying them interactively,
the script-file looks like this:

option batch abort
option confirm off
option transfer ASCII
cd /
get filename_exist.csv
close
exit

and then I start the command with
C:\temp> E:\FTP_Tools\WinSCP\WinSCP.com /console "PROFILE_NAME" /script=E:\FTP_Scripts\0099_wscp.scri

After finishing, I also want to read the errorlevel with
C:\temp> echo %errorlevel%

Regardless of a successful end or not (file exists or not), I get the errorlevel "1" in every situation.

I have tried a lot of things, like
- set retcode=%errorlevel% and echo Returncode %retcode% in order to make sure that the value of the errorlevel is not overwritten
- try all winscp-options that could make sense or not, like option batch abort, option batch on, etc.
- put it all in a bat and start this with and without the call command.
- start the command from within the WinSCP-Folder or not
- . . .

Where am I wrong? Is this maybe a bug in WinSCP.com 4.4.0?

Thank you very much for your help.

Thomas

Reply with quote

Advertisement

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

Re: Errorlevel not as expected

First, your use of WinSCP is not supported. You should not combine scripting and opening session using command-line argument. You should use open command from the script.
See https://winscp.net/eng/docs/commandline

Second, you should really upgrade.

Anyway, to investigate your problem, just turn on logging using /log=log_path switch. If the problem is not obvious, please attach a full log file here.

Reply with quote

MajorTom2004
Joined:
Posts:
7
Location:
Switzerland

Hi Martin.

The tests I've done are very promising, the problem was the winscp.com /console "PROFILE" call.
When I put it as "open PROFILE" into the script, it works ok and brings back exactly what I expect, with the version 4.4.0.

Thank you very much for your help

I wish you a merry christmas!

Thomas

Reply with quote

martin
Site Admin
martin avatar

Thanks for your feedback. I would still like to see a log file of your original setup though. Because the change you've done should not have an effect on the exit code.

Reply with quote

Advertisement

You can post new topics in this forum