[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 740
  • Last Modified:

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)

       
0
bobbailey22
Asked:
bobbailey22
  • 2
  • 2
1 Solution
 
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
 
Mike TomlinsonMiddle 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
 
bobbailey22Author Commented:
You are awesome! If I could give you an A+++ I would.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now