How do I read success/failure in batch?

Advertisement

Sokonomi
Joined:
Posts:
3

How do I read success/failure in batch?

I currently have this script to upload a queue to a tablet;

@echo off
set LOG=%CD%\log.txt
set REMOTE_PATH=/Removable/MicroSD/
echo %date:~-4,4%/%date:~-7,2%/%date:~-10,2% %time:~0,8% QUEUE START >> %LOG%

:LOOP
set /p FILE= < "PPlist.txt"
IF "%FILE%" neq "" (
   echo %date:~-4,4%/%date:~-7,2%/%date:~-10,2% %time:~0,8% UPLOAD ATTEMPT : %FILE% >> %LOG%
   "C:\Program Files (x86)\WinSCP\winscp.com" /command ^
      "option batch abort" ^
      "option confirm off" ^
      "open ftp://xxx:xxx@xxx.xxx.xxx.xxx:xxxx" ^
      "put ""%FILE%"" %REMOTE_PATH%" ^
      "exit"
      IF %ERRORLEVEL% == 0 (
         echo %date:~-4,4%/%date:~-7,2%/%date:~-10,2% %time:~0,8% UPLOAD SUCCESS : %FILE% >> %LOG%
         more /E +1 "PPlist.txt" > "PPlist.txt.new"
         move /y "PPlist.txt.new" "PPlist.txt"
      ) ELSE echo %date:~-4,4%/%date:~-7,2%/%date:~-10,2% %time:~0,8% UPLOAD FAILURE : %FILE% >> %LOG%
      goto LOOP
) ELSE (
   echo %date:~-4,4%/%date:~-7,2%/%date:~-10,2% %time:~0,8% QUEUE COMPLETE >> %LOG%
   exit
)
But its behaving a bit strange.
It seems that when the destination has run out of space,
winscp still exits with errorlevel 0 the first time it loops around.
It does print "Error transferring file" before exiting though.
Am I doing it wrong?

Reply with quote

Advertisement

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

Re: How do I read success/failure in batch?

Please attach a full log file showing the problem (using the latest version of WinSCP).

To generate log file, use /log=path_to_log_file command-line argument. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.

Reply with quote

Sokonomi
Joined:
Posts:
3

Ive attached the log you requested.

I suppose the one line of most importance is
. 2015-05-07 13:45:57.587 Script: Exit code: 1

My hypothesis; WinSCP sets exit code to 1 but doesn't exit,
it gets itself stuck in a loop retrying the transfer instead.

Did I use the wrong command parameters for it to exit upon failure?
Description: Snippet of failed instance.

Reply with quote

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

Sokonomi wrote:

My hypothesis; WinSCP sets exit code to 1 but doesn't exit,
it gets itself stuck in a loop retrying the transfer instead.
You wrote before that WinSCP exits with code 0. So how does that go along with new hypothesis that it does not exit at all?

The log indicates that WinSCP behaves as expected.

Reply with quote

Sokonomi
Joined:
Posts:
3

Then why does it exit with exitcode 0 the first time around even though it failed to upload?

Because either the loop that is happening is staying within winscp,
or the loop is happening because the batch code is getting the wrong exit code.

Reply with quote

Advertisement

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

Sokonomi wrote:

Then why does it exit with exitcode 0 the first time around even though it failed to upload?

Because either the loop that is happening is staying within winscp,
or the loop is happening because the batch code is getting the wrong exit code.
Application does NOT have an exit code when it does not exit.

Reply with quote

Advertisement

You can post new topics in this forum