2014-10-07 180 views
4

使用Unity3D和編輯器腳本嘗試在osx上的終端中運行腳本。Unity c#運行shell腳本

從終端運行test.sh時,GDCL應用程序執行它的操作並輸出參數。但是,如果我從Unity3D編輯器運行腳本,則只會在輸出中獲取參數。 GDCL不運行。

如何讓Unity3D運行終端腳本?運行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腳本文件模式

C#腳本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 
+0

凡GDCL位於磁盤上?它在路上嗎? – 2015-09-08 17:42:14

回答

0

嘗試將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"; 
0

嘗試這GDLC在終端,得到完整的路徑,而不是在GDLC和test.sh使用完整路徑,然後它會工作