Defining a working directory for program execution (C #)

I am currently trying to run an executable from a specific folder.

The code that I have below calls a rather strange application:

Process p = new Process();
p.StartInfo.WorkingDirectory = "dump";
p.StartInfo.FileName = s;
p.Start();

I debugged it and it said that it cannot find the file to run, but the file / folder defintly exists, is my syntax bad?

The code below works, but the working directroy is not defined, so it cannot find the executable

Process.Start(@"dump\", s);
+5
source share
2 answers

The working directory that you installed ("dump") refers to the current working directory. You might want to check the current working directory.

...

string exeDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
Directory.SetCurrentDirectory(exeDir);

, , , p.StartInfo.WorkingDirectory .

+9

, . , Process .

0

All Articles