如果调用外部普通应用程序, 比如notepad.exe 这样调用
static public bool ExecuteProgram(string exeFilename, string workDir, string args)
{
System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo();
info.FileName = exeFilename;
info.WorkingDirectory = workDir;
info.RedirectStandardOutput = true;
info.RedirectStandardError = true;
info.Arguments = args;
info.UseShellExecute = false;
info.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
System.Diagnostics.Process task = null;
bool rt = true;
try
{
task = System.Diagnostics.Process.Start(info);
if (task != null)
{
task.WaitForExit(10000);
}
else
{
return false;
}
}
catch (Exception e)
{
Debug.LogError("Error: " + e.ToString());
return false;
}
finally
{
if (task != null && task.HasExited)
{
string output = task.StandardError.ReadToEnd();
if (output.Length > 0)
{
Debug.LogError(output);
}