C#程序A调用程序B,如果程序B中存在
string path1 = System.Environment.CurrentDirectory;
程序A中开启B进程的代码为:
System.Diagnostics.Process.Start(@"E:\VS2010\2016-10-20\ConsoleApplication1\bin\Debug\ConsoleApplication1.exe");
Process p = new Process();
p.StartInfo.FileName = file;
p.Start();
此时B程序中path1的值为A程序的.exe的路径,如果想要path1的值还为B程序的.exe的路径,可以这样写
System.Diagnostics.Process.Start(@"E:\VS2010\2016-10-20\ConsoleApplication1\bin\Debug\ConsoleApplication1.exe");
Process p = new Process();
p.StartInfo.FileName = file;
p.StartInfo.WorkingDirectory = @"E:\VS2010\2016-10-20\ConsoleApplication1\bin\Debug";
p.Start();