Unity c# 运行 shell 脚本

6
使用Unity3D和编辑器脚本尝试在OSX终端中运行脚本。当从终端运行test.sh时,GDCL应用程序会执行其任务,然后输出参数。但是,如果我从Unity3D编辑器运行脚本,则只能在输出中获取参数。 GDCL不运行。 如何让Unity3D运行终端脚本? C#脚本运行test.sh(仅提供输出)。
ProcessStartInfo psi = new ProcessStartInfo(); 
psi.FileName = Application.dataPath+"/test.sh";
psi.UseShellExecute = false; 
psi.RedirectStandardOutput = true;
psi.Arguments = "arg1 arg2 arg3";

//psi.Arguments = "test"; 
Process p = Process.Start(psi); 
string strOutput = p.StandardOutput.ReadToEnd(); 
p.WaitForExit(); 
UnityEngine.Debug.Log(strOutput);

test.sh脚本已经调整为chmod 777 (GDCL仅在终端中工作)

#!/bin/sh
GDCL ~/Documents/Unity/testproject/Assets/Font\ Normal.GlyphProject ~/Documents/Unity/testproject/Assets/Textures/fontNormal/font -fo PlainText-txt
for arg in $*
do
    echo $arg
done

GDCL在磁盘上的位置在哪里?它是否在路径中? - Clay Fowler
2个回答

3
尝试将UseShellExecute设置为true,或直接运行您的shell并将脚本作为第一个参数传递。
psi.UseShellExecute = true; 

或者

ProcessStartInfo psi = new ProcessStartInfo(); 
psi.FileName = "/bin/sh";
psi.UseShellExecute = false; 
psi.RedirectStandardOutput = true;
psi.Arguments = Application.dataPath + "/test.sh" + " arg1 arg2 arg3";

不要忘记导入:

using System.Diagnostics;

0

尝试在终端中使用GDLC,获取完整路径,然后在test.sh中使用完整路径而不是GDLC,这样它就可以工作了。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接