Launching An External Program

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Keith French

    #1

    Launching An External Program

    I am trying to launch an external program within Visual Basic 2005 Express.
    If it is a simple program it works well with:-

    myProg = "C:\MyFolder\My App.exe"
    System.Diagnost ics.Process.Sta rt(myProg)

    However, the application in question needs various command line arguments
    added when it is launched, such as:-

    "C:\MyFolder\My App.exe -h 9 -r 55 -j testfile.abc"

    When I try this a Win32Exception was handled because it says it cannot find
    the file specified. I am sure the problem is in how the arguments are
    handled. Any ideas please?





  • beaker

    #2
    Re: Launching An External Program

    Keith French wrote:[color=blue]
    > I am trying to launch an external program within Visual Basic 2005 Express.
    > If it is a simple program it works well with:-
    >
    > myProg = "C:\MyFolder\My App.exe"
    > System.Diagnost ics.Process.Sta rt(myProg)
    >
    > However, the application in question needs various command line arguments
    > added when it is launched, such as:-
    >
    > "C:\MyFolder\My App.exe -h 9 -r 55 -j testfile.abc"
    >
    > When I try this a Win32Exception was handled because it says it cannot find
    > the file specified. I am sure the problem is in how the arguments are
    > handled. Any ideas please?
    >[/color]

    Are you just changing your myProg string to include MyApp's arguments?

    Have you tried setting the arguments with Process's 'startInfo.Argu ments'?

    Comment

    • Herfried K. Wagner [MVP]

      #3
      Re: Launching An External Program

      "Keith French" <keithfrench@bt connect.com> schrieb:[color=blue]
      >I am trying to launch an external program within Visual Basic 2005 Express.
      >If it is a simple program it works well with:-
      >
      > myProg = "C:\MyFolder\My App.exe"
      > System.Diagnost ics.Process.Sta rt(myProg)
      >
      > However, the application in question needs various command line arguments
      > added when it is launched, such as:-
      >
      > "C:\MyFolder\My App.exe -h 9 -r 55 -j testfile.abc"[/color]


      Check out 'Process.Start( <file name>, <arguments>)' .

      --
      M S Herfried K. Wagner
      M V P <URL:http://dotnet.mvps.org/>
      V B <URL:http://classicvb.org/petition/>

      Comment

      • Keith French

        #4
        Re: Launching An External Program

        No I haven't tried that. Can you give me the syntax or point me to a good
        web reference please?


        "beaker" <blahblah@rhuba rbrhubarbblahbl ah.net> wrote in message
        news:en4NVEazFH A.3856@tk2msftn gp13.phx.gbl...[color=blue]
        > Keith French wrote:[color=green]
        >> I am trying to launch an external program within Visual Basic 2005
        >> Express. If it is a simple program it works well with:-
        >>
        >> myProg = "C:\MyFolder\My App.exe"
        >> System.Diagnost ics.Process.Sta rt(myProg)
        >>
        >> However, the application in question needs various command line arguments
        >> added when it is launched, such as:-
        >>
        >> "C:\MyFolder\My App.exe -h 9 -r 55 -j testfile.abc"
        >>
        >> When I try this a Win32Exception was handled because it says it cannot
        >> find the file specified. I am sure the problem is in how the arguments
        >> are handled. Any ideas please?
        >>[/color]
        >
        > Are you just changing your myProg string to include MyApp's arguments?
        >
        > Have you tried setting the arguments with Process's 'startInfo.Argu ments'?
        >[/color]


        Comment

        • Herfried K. Wagner [MVP]

          #5
          Re: Launching An External Program

          "Keith French" <keithfrench@bt connect.com> schrieb:[color=blue]
          > No I haven't tried that. Can you give me the syntax or point me to a good
          > web reference please?[/color]

          ..NET Framework Class Library -- 'ProcessStartIn fo' Class
          <URL:http://msdn.microsoft. com/library/en-us/cpref/html/frlrfsystemdiag nosticsprocesss tartinfoclassto pic.asp>

          --
          M S Herfried K. Wagner
          M V P <URL:http://dotnet.mvps.org/>
          V B <URL:http://classicvb.org/petition/>

          Comment

          • Keith French

            #6
            Re: Launching An External Program

            Thanks for that it now handles the arguments fine using:-

            'Process.Start( <file name>, <arguments>)

            However, the program I am launching is a DOS program and you stop its
            display with CTRL-C, which works, the problem is this also closes the
            command prompt window it runs it. I need to see some output of the results
            of this program and hence need to keep the window open.

            Is there a way of doing this as well?


            "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
            news:OgX$szbzFH A.3180@TK2MSFTN GP14.phx.gbl...[color=blue]
            > "Keith French" <keithfrench@bt connect.com> schrieb:[color=green]
            >>I am trying to launch an external program within Visual Basic 2005
            >>Express. If it is a simple program it works well with:-
            >>
            >> myProg = "C:\MyFolder\My App.exe"
            >> System.Diagnost ics.Process.Sta rt(myProg)
            >>
            >> However, the application in question needs various command line arguments
            >> added when it is launched, such as:-
            >>
            >> "C:\MyFolder\My App.exe -h 9 -r 55 -j testfile.abc"[/color]
            >
            >
            > Check out 'Process.Start( <file name>, <arguments>)' .
            >
            > --
            > M S Herfried K. Wagner
            > M V P <URL:http://dotnet.mvps.org/>
            > V B <URL:http://classicvb.org/petition/>[/color]


            Comment

            • Herfried K. Wagner [MVP]

              #7
              Re: Launching An External Program

              Keith,

              "Keith French" <keithfrench@bt connect.com> schrieb:[color=blue]
              > However, the program I am launching is a DOS program and you stop its
              > display with CTRL-C, which works, the problem is this also closes the
              > command prompt window it runs it. I need to see some output of the results
              > of this program and hence need to keep the window open.[/color]

              You could redirect the application's output:

              <URL:http://dotnet.mvps.org/dotnet/samples/misc/RedirectConsole .zip>

              --
              M S Herfried K. Wagner
              M V P <URL:http://dotnet.mvps.org/>
              V B <URL:http://classicvb.org/petition/>

              Comment

              • Keith French

                #8
                Re: Launching An External Program

                Thanks for that it works now. The only thing is that I have to terminate my
                DOS program with CTRL-C, which should just stop it running and not close the
                window. This way you can read the results from its run. Is there a way to
                keep the window open? What about running "cmd.exe" as the program and my
                program as arguments off of CMD.exe?



                "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
                news:OgX$szbzFH A.3180@TK2MSFTN GP14.phx.gbl...[color=blue]
                > "Keith French" <keithfrench@bt connect.com> schrieb:[color=green]
                >>I am trying to launch an external program within Visual Basic 2005
                >>Express. If it is a simple program it works well with:-
                >>
                >> myProg = "C:\MyFolder\My App.exe"
                >> System.Diagnost ics.Process.Sta rt(myProg)
                >>
                >> However, the application in question needs various command line arguments
                >> added when it is launched, such as:-
                >>
                >> "C:\MyFolder\My App.exe -h 9 -r 55 -j testfile.abc"[/color]
                >
                >
                > Check out 'Process.Start( <file name>, <arguments>)' .
                >
                > --
                > M S Herfried K. Wagner
                > M V P <URL:http://dotnet.mvps.org/>
                > V B <URL:http://classicvb.org/petition/>[/color]


                Comment

                • Herfried K. Wagner [MVP]

                  #9
                  Re: Launching An External Program

                  "Keith French" <keithfrench@bt connect.com> schrieb:[color=blue]
                  > Thanks for that it works now. The only thing is that I have to terminate
                  > my DOS program with CTRL-C, which should just stop it running and not
                  > close the window. This way you can read the results from its run. Is there
                  > a way to keep the window open?[/color]

                  I don't know if this is possible, but I assume it's not.
                  [color=blue]
                  > What about running "cmd.exe" as the program and my program as arguments
                  > off of CMD.exe?[/color]

                  "cmd.exe" doesn't expect a file to run as parameter, IIRC. However, you
                  could create a batch file which starts the executable and then uses 'PAUSE'
                  to keep the console open.

                  --
                  M S Herfried K. Wagner
                  M V P <URL:http://dotnet.mvps.org/>
                  V B <URL:http://classicvb.org/petition/>

                  Comment

                  Working...