Unity中使用Process注意事项

  在unity中,要调用外部程序处理时,常见代码如下:

Process proc = Process.Start(new ProcessStartInfo
{
FileName = LuacToolPath,
Arguments = " -o " + newPath + " " + luaPath,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true
});
if (proc != null)
{
proc.WaitForExit();
string stdOutput = proc.StandardOutput.ReadToEnd();
if (stdOutput.Length > 0)
UnityEngine.Debug.LogError(stdOutput);
string errOutput = proc.StandardError.ReadToEnd();
if (errOutput.Length > 0)
UnityEngine.Debug.LogError(errOutput);
}

此处需要注意的是:如仅重定向error输出,可能导致unity假死(如luac编译文件报错)。加上output定向后一切正常。。。

原文地址:https://www.cnblogs.com/hghhe/p/14449091.html