Question Process.Start()

arahman

Member
Joined
Oct 14, 2013
Messages
5
Programming Experience
Beginner
Hey everyone! I need urgent help with this issue I am having with the process.start command.

So, I have a .exe file that takes in a text file as an argument and generates another text file as an output. Now, when I am trying to access my .exe file with process.start with the text file using

"Process.Start("C:\Users\DirectStiffness.exe", "C:\Users\HW3A.txt")

the program does not run and says file could not be opened.

I have tried opening the program with cmd process and it works fine over there. This tells me that the .exe file is working fine.

I have also tried opening the program and the file in numerous other ways, but I have failed to make it work. Any help would be greatly appreciated.
Thanks!
 
A common gotcha when using Process.Start is the working directory. You know how, when you create a shortcut on the desktop or Start menu, you can set the working directory? That tells the application what folder path to use by default if one is not specified, e.g. if it tries to open or create a file by name with no path, it will assume that folder. When you run an application from the command prompt, it uses the folder containing the EXE as the working directory.

When you call Process.Start, by default, it will use the current directory of your app. If the other app uses its working directory, that default will almost certainly be wrong. Usually you want to specify the folder containing the new EXE as its own working directory. To do that, create a ProcessStartInfo object, configure it and pass that to Process.Start.
 
Thanks a lot for your reply, but I am not too sure how to go ahead about doing that. I am a complete beginner to coding. This is what I am currently doing,

Dim a As New ProcessStartInfo
a.FileName = "C:\Users\Asim Rahman\Desktop\Project Input Files\DirectStiffness.exe"
a.Arguments = "-C:\Users\Asim Rahman\Desktop\Project Input Files\HW3B.txt"
a.WindowStyle = ProcessWindowStyle.Maximized
Process.Start(a)
 
I said that you need to set the working directory. Have you looked at the ProcessStartInfo object to see how you can do that?

By the way, should that dash actually be there before the text file path? Usually you only use dashes or slashes on switches, although that's up to the application developer. Do you use a dash when running from a command prompt?
 
I dont actually use the dash in cmd. I have taken it out from here but the results the same. I have been looking stuff online for ProcessStartInfo but have not figured out how to change the working directory. can you please show me an example?
 
Um, maybe setting the WorkingDirectory property would be helpful. Excuse my sarcasm but that really is about as obvious as it gets. If you didn't know that there was a WorkingDirectory property then that means that you haven't used to Help menu on the IDE to open the documentation for the ProcessStartInfo class, which should have been the very first thing you did.

As for the dash, if you don't use it at the commandline then don't use it here. You use EXACTLY the same commandline arguments in both cases.
 
Back
Top