尊重原创,转载请在文首注明出处:http://blog.csdn.net/cai612781/article/details/79030654
一,语法
C#提供Process类来对本地或远程进程进行访问,以及启动或停止本地进程。
更多语法信息:https://msdn.microsoft.com/zh-cn/library/system.diagnostics.process.aspx
二,代码
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using Debug = UnityEngine.Debug;
namespace Assets.Editor
{
public class EditorUtil
{
public static void ExecuteProcess(string filePath, string command, string workPath = "", int seconds = 0)
{
if (string.IsNullOrEmpty(filePath))
{
return;
}
Process process = new Process();//创建进程对象
process.StartInfo.WorkingDirectory = workPath;
process.StartInfo.FileName = filePath;
process.StartInfo.Arguments = command;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardOutput = false;//不重定向输出
try
{
if (process.Start())
{
if (seconds == 0)
{
process.WaitForExit(); //无限等待进程结束
}
else
{
process.WaitForExit(seconds); //等待毫秒
}
}
}
catch (Exception e)
{
Debug.LogError(e.Message);
}
finally
{
process.Close();
}
}
}
}