Error Level Not being returned?

Advertisement

BICKY1980
Joined:
Posts:
6

Error Level Not being returned?

I have a command which I execute using T-SQL. The command runs fine but the errorlevel does not get returned to SQL.

The command I am running is: (I am purposely specifying a file which does not exists to get the error code)

c:\winscp.com /console /command "option batch abort" "option confirm off" "open ftp://[hiddenFTPdetails]" "put c:\work\test3.txt" "exit" & ECHO errorcode=%ERRORLEVEL%

The following gets returned?

batch           abort     
confirm         off       
Connecting to ftp://[hiddenFTPdetails] ...
Connected with ftp://[hiddenFTPdetails] Waiting for welcome message...
Connected
Starting the session...
Reading remote directory...
Session started.
Active session: [1] ftp://[hiddenFTPdetails]
File or folder 'c:\work\test3.txt' does not exist.
System Error.  Code: 2.
The system cannot find the file specified 
(A)bort, (R)etry, (S)kip, Ski(p) all: Abort
errorcode=0
NULL

As you can see the System Error code is being returned correctly but the errorlevel (System Error. Code: 2.) being read back to SQL is 0 (errorcode=0) - how do i echo the system error code

Please help

Thanks

Reply with quote

Advertisement

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

Re: Error Level Not being returned?

Environment variables on one line (no matter if that line includes multiple commands using &) are resolved BEFORE that line is executed.
Try dir nonexisting & echo %ERRORLEVEL%. You will also get 0.

Reply with quote

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

First, you cannot get the "System Error 2" back via WinSCP exit code. WinSCP return always 0 or 1.
I just wanted to point out that your test with & ECHO errorcode=%ERRORLEVEL% is irrelevant.

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 may email it to me. You will find my address (if you log in) in my forum profile. Please include link back to this topic in your email. Also note in this topic that you have emailed the log.

Reply with quote

BICKY1980
Joined:
Posts:
6

Thanks for the clarification.

What I need to be able to do is run winscp via the command line and if anything fails for whatever reason I want to be informed of it. Having a code returned would be ideal which is why ideally I was wanting the system error code as this specified the exact problem. I have been using XP_cmdshell on SQL Server which runs it fine but when I encounter a problem I need winscp to inform me.

The command I am running is:

c:\winscp.com /console /command "option batch abort" "option confirm off" "open ftp://[hiddenFTPdetails]" "put c:\work\test3.txt" "exit"

If I could still make use of the return code what would the correct syntax be? (Log file attached if this helps??)

Reply with quote

Advertisement

martin
Site Admin
martin avatar

I cannot support an ancient version of WinSCP you are using. Please upgrade to the latest version and post a log file using it (for session, where WinSCP fails).

Reply with quote

Advertisement

You can post new topics in this forum