I am trying to write a powershell script which call the .ftp file (http://www.scriptftp.com). When Powershell call the .ftp script file which is use to upload a zip file to ftp server
here is my upload.ftp file code
OPENHOST("www.abcd.in","sdfdsfs","pwd")
CHDIR("/dirctory/from/user/")
$result=PUTFILE("D:\MyZipTest.zip")
IF($result!="OK")
PRINT("ERROR in GetFile, exiting")
# Exit with error code 1
EXIT(1)
ELSE
EXIT()
PRINT("File uploaded successfuly")
END IF
CLOSEHOST
In Above code i return EXIT(1) or EXIT(0) to calling method ie powershell script file
my powershell script file code:
Invoke-Item "D:\USER\Raj\BLACKswastik DEV\FTPScript\Upload1.ftp"
Start-Sleep -Second 15
echo $lastexitcode
echo $?
here i want to fetch exit code which return by .ftp file script so i use $lastexitcode and $? but both of them not showing me proper results.
IS there any other way to fetch the exit code of child process please suggest me.
Try using
Start-Process. You can get back aProcessobject that you can query later for an exit code e.g.:The problem with using Invoke-Expression (or launching the exe directly) is that you’re launching a Windows subsystem EXE and unlike a console subsystem exe, Invoke-Expression will return right after the exe has launched (and before it exits). Invoke-Item also returns before the Windows EXE has exited.