Link to home
Start Free TrialLog in
Avatar of bobbailey22
bobbailey22

asked on

Capture return code from Shell App

Experts,

The FTPS (MOVEit Freely Secure FTP) Application that is called in the Shell() below will return an error code (0 if successful). How can I capture the return code that FTPS returns?

        Dim ProcID
        ' Execure Secure FTP
        ProcID = Shell("FTPS -e:on -z -s:""C:\HCC_Upload_Files\FtpUploadScript.TXT"" sftp.domain.com", AppWinStyle.NormalFocus, True, 120000)

       
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Don't use Shell().  Instead use the Process() class:

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim p As Process
        p = Process.Start("FTPS -e:on -z -s:""C:\HCC_Upload_Files\FtpUploadScript.TXT"" sftp.domain.com")
        p.WaitForExit()
        Dim exitCode As Integer = p.ExitCode
        MsgBox("exitCode = " & exitCode)
    End Sub
   
Avatar of bobbailey22
bobbailey22

ASKER

Idle_Mind,

I was really excited about your solution (love learning new stuff) but I keep getting the following error when the Process.Start line is executed...

An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in system.dll
Additional information: The system cannot find the file specified

I also tried qualifying the executable like so...

p = Process.Start("""C:\Program Files\MOVEit\FTPS.exe"" -e:on -z -s:""C:\HCC_Upload_Files\FtpUploadScript.TXT"" sftp.hcclife.com")

but got the same error.

I know the text file path and name are good.

Any Ideas????
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You are awesome! If I could give you an A+++ I would.