Yeasin Abedin
Yeasin Abedin

Reputation: 2443

.exe not running from it's original directory from C# using Process

I have two console app projects (prj1 and prj2).

I have EF6 code first in prj2, build and then copied it's "Debug" folder into a separate directory (example : "D:\Debug").

In prj1, I am trying to run prj2 using :

Process p = new Process
{
    StartInfo = new ProcessStartInfo("D:\\Debug\\prj2.exe")
};
p.Start(); 

Problem is, database is being created inside prj1's Debug folder (not in "D:\Debug"

But if I run the .exe of prj2 directly from "D:\Debug\prj2.exe" by double-click - everything works fine.

Upvotes: 0

Views: 51

Answers (2)

Doğukan Tunç
Doğukan Tunç

Reputation: 347

You have to change your working (active) directory.

https://msdn.microsoft.com/en-us/library/system.io.directory.setcurrentdirectory(v=vs.110).aspx

Upvotes: 1

No Em
No Em

Reputation: 59

I think you should try with ProcessStartInfo.WorkingDirectory

var startInfo = new ProcessStartInfo("D:\\Debug\\prj2.exe");
startInfo.WorkingDirectory = "D:\\Debug";
Process p = new Process();
p.StartInfo = startInfo;
p.Start(); 

Upvotes: 1

Related Questions