Topic "Scripting in Powershell"

Author Message
floschn

Guest


Hello,

I’m not sure if this is a Bug or I am missing something here. But maybe some could help me with my problem. I like to script and FTP Transfer from Powershell. So far everything works fine but not the exit codes.

For a small test I made 2 commad scripts one that works and one that will fail. When I do let them run from batch the exit codes return fine.

Quote:
winscp.exe /console /script=test1.txt /log=ftp.log
ErrorLevel 0

winscp.exe /console /script=test2.txt /log=ftp.log
ErrorLevel 1

pause
Press any key to continue . . .


But from Powershell I always get an “0” as return code.

Quote:
.\test1.ps1
0
0

Code of powershellscript:

Code:
.\winscp.exe /console /script=test1.txt /log=ftp.log
$LASTEXITCODE
.\winscp.exe /console /script=test2.txt /log=ftp.log
$LASTEXITCODE


ftp.log shows following line:
Quote:
. 2014-01-15 12:24:51.561 Script: Failed
. 2014-01-15 12:24:51.561 Script: Exit code: 1
. 2014-01-15 12:24:51.561 Disconnected from server
< 2014-01-15 12:24:51.567 226 Closing data connection

Exit Codes from Powershell:
https://blogs.msdn.microsoft.com/powershell/2006/09/15/errorlevel-equivalent/
i tried by myself with ping and the sc command. On both the exit codes worked.
Has anyone got this working on WinSCP or does have an idea how to sovle this. (i don't want to use batch)
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25015
Location: Prague, Czechia
The winscp.exe is a GUI application. PowerShell does not seem to wait for GUI application to exit before proceeding to the next comment. So the $LASTEXITCODE cannot contain the exit code as the application has not exited yet. Use winscp.com instead, what is a console application.
https://winscp.net/eng/docs/executables
floschn

Guest


Thank You for your reply,

i will try it as soon as i am home.

THANKS!
floschn

Guest


thanks worked like a charm !

regards
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