Unity中使用c# Process在Mac上异常Win32Exception:
http://blog.dou.li/Process-Mac-Win32Exception.html
在Unity中调用TexturePacker打包图集,核心代码如下:
Process p = new Process ();
p.StartInfo.FileName = "TexturePacker";
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
p.WaitForExit();
在Windows上运行正常,Mac上报异常:
Win32Exception: ApplicationName='TexturePacker', CommandLine='',
CurrentDirectory='' System.Diagnostics.Process.Start_noshell
(System.Diagnostics.ProcessStartInfo startInfo,
System.Diagnostics.Process process)
System.Diagnostics.Process.Start_common
(System.Diagnostics.ProcessStartInfo startInfo,
System.Diagnostics.Process process) System.Diagnostics.Process.Start
() (wrapper remoting-invoke-with-check)
System.Diagnostics.Process:Start ()
一番查找发现,Mac上应该用open命令调用目标应用,Mac版本的代码修改如下:
Process p = new Process ();
p.StartInfo.FileName = "open";
p.StartInfo.Arguments = "-a TexturePacker -n --args xxx";
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
p.WaitForExit();
-n
启动新的TexturePacker实例--args
后面跟TexturePacker需要的参数
转载请注明:兜里-http://blog.dou.li/Process-Mac-Win32Exception.html