I am currently trying to get an executable to be launched from a specific folder.
The code I have below crashes the application oddly enough:
Process p = new Process();
p.StartInfo.WorkingDirectory = "dump";
p.StartInfo.FileName = s;
p.Start();
I debugged it, and it was saying it can't find the file to start, but the file / folder defintly exists, is my syntax bad?
The code below works, but a working directroy is not defined, so it can't find the executable
Process.Start(@"dump\", s);
The working directory that you set ("dump") is relative to the current working directory. You might want to check the current working directory.
You should be able to set the working directory to the executing assemblies directory with this code...
string exeDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
Directory.SetCurrentDirectory(exeDir);
Or, better yet, don't use a relative path, set p.StartInfo.WorkingDirectory to the absolute path.
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