Search code examples
c#process.start

Process.start environment path


I have console application 1 which write text to file and it is in C:/app1

using (StreamWriter k = new StreamWriter("777.txt"))
    k.WriteLine("aa");

I have another console application 2, c:/app2, which start console application 1

System.Diagnostics.Process.Start("c:/app1/app1.exe");

For some reason, when I run application 2, the output 777.txt will be in folder2 instead of folder1. When I run application 1 from windows explorer, the output 777.txt will be in folder1.

I look and tried to add environment.path but it didn't solve the problem.


Solution

  • Please try the following:

            ProcessStartInfo startInfo = new ProcessStartInfo(@"c:\app1\app1.exe");
            startInfo.WorkingDirectory= @"c:\app1";
    
            Process.Start(startInfo);