VB.NET....sending command line arguments via process.start

Associate
Joined
27 Jan 2005
Posts
1,396
Location
S. Yorks
Hi,

I have written a program that opens a DOS program that sits waiting for a filename to be input, how do I pass the name of a file to the started process.

I asked the question elsewhere to be told that I could probaly do it by passing command line arguments to the started process - so how do I do this???

regards,

Matt
 
I have a visual way of selecting the file, common dialog, but the dos program requires the filename input inorder to process it.

regards,

Matt
 
Depends on your dos program and if it will accept command line arguments.

Code:
                Dim p As New ProcessStartInfo()
                p.CreateNoWindow = True
                p.WindowStyle = ProcessWindowStyle.Hidden
                p.FileName = "myprog.bat"
                p.Arguments = "c:\deleteme.jpg"
                Dim pr As Process = Process.Start(p)
                pr.WaitForExit()
                pr = Nothing
                p = Nothing

I think you want to run an external program, but to pass the filename to this, rather than the user typing the filename. It would help if you told us the dos program.
 
Thanx for that...

The Dos program is a compiled fortran scientific program - with no manuals or anything.

Question if I include the arguments as you have shown does that act in a similar way to if I wrote a batch file as follows:

myprog.exe myfile.txt


Where myprog is the compiled fortran program and myfile.txt the text file requiring processing??

If this is how it works then, I have tried this and the fortran program doesn't accept arguments, it just loads and asks the user to input a filename.

regards,

Matt
 
If your compiled exe program will let you do at a dos command window "program.exe filename" command line arguements can be accepted. Perhaps try "program.exe --help" or "program.exe ?" from dos.

Programs have to be made to accept arguments. It could be the case yours doesn't.
 
It won't accept the command line arguements as typing the exe name then filename doesn't work it just starts the exe.

Is there any way of passing the filename then??

regards,

Matt

P.S. I have tried sendkeys all this does is pass a backslash to the dos program, no matter what you send.
 
Tbh and if it was me as a nasty hack yes sendkeys should do the job.

Sendkeys will be dodgy. You will have to run the exe process, ensure focus of the window takes places - delay before sending the filename, then send the filename via sendkeys.

If your doing this lots of times there is bound to be problems with the window focus being lost.

I don't see why only a black slash is sent. Try it but with long delays and really slowly. So you can see if anything is happening.
 
Will give it another try tomorow...

I wasn't sure if sendkeys would only work with a prog designed to run under windows, obviously the prog I am running is designed to work only under Dos.

regards,

Matt
 
Have tried sendkeys again and all I get is the \ character displaying, if I send a filename where the file doesn't exist I get several \'s, which is weird.

I have received an email suggesting that in VB6 you could use API calls to o this, am new to VB so any help would e appreciated.

Anyone else got any better ideas?

regards,

Matt
 
Sendkeys should just emulate the keyboard.

Have you tried sendkeys in VB6 rather than .Net.

Hooking into the program without documentation would be difficult.

Wouldn't it just be easier to rewrite what this program does in VB?
 
Sendkeys in vb and vb.net just puts up a \ character.

It would be nice to rewrite the program in VB, but it is a scientific modelling program - hence complex.

I am thinking it may be a better idea to get a Fortran compiler, make a basic program and then see if I can link into this somehow?? :confused:

regards,

Matt
 
Back
Top Bottom