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)

       
bobbailey22Asked:
Who is Participating?
 
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
Here is an alternate usage that may work for you:


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim p As New Process
        p.StartInfo.FileName = "C:\Program Files\MOVEit\FTPS.exe"
        p.StartInfo.Arguments = "-e:on -z -s:""C:\HCC_Upload_Files\FtpUploadScript.TXT"" sftp.hcclife.com"
        p.Start()
        p.WaitForExit()
        Dim exitCode As Integer = p.ExitCode
        MsgBox("exitCode = " & exitCode)
    End Sub

0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
   
0
 
bobbailey22Author Commented:
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????
0
 
bobbailey22Author Commented:
You are awesome! If I could give you an A+++ I would.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.