I have an .exe
file that needs to be run after I create a file. The file is successfully created and I am using the following code to run the .exe
file after that:
ProcessStartInfo processInfo = new ProcessStartInfo();
processInfo.FileName = pathToMyExe;
processInfo.ErrorDialog = true;
processInfo.UseShellExecute = false;
processInfo.RedirectStandardOutput = true;
processInfo.RedirectStandardError = true;
Process proc = Process.Start(processInfo);
I also tried with a simple Process.Start(pathToMyExe);
but the .exe
file is not run. When I try pathToMyExe
manually on my Windows Explorer the program is correctly run. But not via the program. What I see is the cursor turning to waiting for a few seconds and then back to normal. So there are no Exceptions thrown either. What is blocking the file?
You are not setting the working directory path, and unlike when starting the application through Explorer, it isn't set automatically to the location of the executable.
Just do something like this:
processInfo.WorkingDirectory = Path.GetDirectoryName(pathToMyExe);
(assuming the input files, DLLs etc. are in that directory)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With