0%

CSharp执行外部exe

前面啥也没有

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
public void ExecuteWithOutput(string path, string exeName)//执行外部exe文件;
{
try
{
if (!System.IO.File.Exists(path + exeName + "\\" + exeName + ".exe"))
{
xErrorOutException(new Exception("请确认" + exeName + "文件路径配置是否正确"));
return;
}
//Process ps = Process.Start(cmdExe);
//ps.WaitForExit();
using (System.Diagnostics.Process cmdProcess = new System.Diagnostics.Process())
{
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();
psi.UseShellExecute = false;
psi.RedirectStandardInput = true;
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
psi.CreateNoWindow = true;
psi.FileName = path + exeName + "\\" + exeName + ".exe";
psi.WorkingDirectory = path + exeName + "\\";
cmdProcess.StartInfo = psi;
cmdProcess.Start();
//string output = cmdProcess.StandardOutput.ReadToEnd();
cmdProcess.WaitForExit();
cmdProcess.Dispose();
}
}
catch(Exception ex)
{
xErrorOutException(ex);
}
}