Launching An External Program

K

Keith French

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\MyApp.exe"
System.Diagnostics.Process.Start(myProg)

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

"C:\MyFolder\MyApp.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?
 
B

beaker

Keith said:
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\MyApp.exe"
System.Diagnostics.Process.Start(myProg)

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

"C:\MyFolder\MyApp.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?

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

Have you tried setting the arguments with Process's 'startInfo.Arguments'?
 
H

Herfried K. Wagner [MVP]

Keith French said:
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\MyApp.exe"
System.Diagnostics.Process.Start(myProg)

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

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


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

Keith French

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

Keith French

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?
 
K

Keith French

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?
 
H

Herfried K. Wagner [MVP]

Keith French said:
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?

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

"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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top