Scripting in Powershell

Advertisement

floschn
Guest

Scripting in Powershell

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.

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.

.\test1.ps1
0
0
Code of powershellscript:

.\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:
. 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://devblogs.microsoft.com/powershell/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)

Reply with quote

Advertisement

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

Re: Scripting in Powershell

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

Reply with quote

Advertisement

You can post new topics in this forum