在项目里经常会用到,在程序里调用另一个程序,再次记录一下
首先用到这个类
- 提供对本地和远程进程的访问并使您能够启动和停止本地系统进程。
- 它表示启动该进程时要使用的数据。这些参数包括用于启动该进程的可执行文件或文档的名称
调用代码示例
string pPath = exePath;
Process p = new Process();
p.StartInfo.FileName = "cmd";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
// string str = "F:";
string str = pPath.Substring(0, 2);
p.StandardInput.WriteLine(str);
// str = "cd " + "\"F:\\Program Files\\Rovio\\Angry Birds Star Wars\"";
str = "cd " + "\"" + pPath.Substring(0, pPath.LastIndexOf("\\") + 1) + "\"";
p.StandardInput.WriteLine(str);
// str = "AngryBirdsStarWars.exe";
str = "\"" + pPath + "\"";
p.StandardInput.WriteLine(str);