Unity c # run shell script

Using Unity3D and a script editor trying to run a script in an osx terminal.

When running test.sh from the terminal, the GDCL application does its job and then outputs the arguments. But if I run the script from the Unity3D editor, I only get the arguments in the output. GDCL does not start.

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); 

There is chmod 777 in test.sh script (GDCL only works from the 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 
+5
source share
2 answers

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"; 
0
source

try which GDLC in the terminal, get the full path and instead of the GDLC in test.sh use the full path, then it will work

0
source

Source: https://habr.com/ru/post/1204172/


All Articles