Using Unity3D and from editor script trying to run a script in the terminal on osx.
When running test.sh from terminal the GDCL application does its thing and then outputs the arguments. But if I run the script from Unity3D editor I only get the arguments in the output. GDCL doesn't run.
How can I get Unity3D to run terminal scripts?
C# script that runs test.sh (gives only output)
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);
The test.sh script has chmod 777 (GDCL works only from terminal)
#!/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
Try setting UseShellExecute to true or try running your shell directly and passing the script as the first argument.
psi.UseShellExecute = true;
Or
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "/bin/sh";
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
psi.Arguments = Application.dataPath + "/test.sh" + " arg1 arg2 arg3";
Don't forget to import:
using System.Diagnostics;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With