Hi all! Is there a way to run a bash script (with args) from C# inside unity? Many thanks for help! Stefano
You can use https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.process.start?view=netframework-4.8 However you will of course need to make sure that bash is installed for this to work.
I wrote this: System.Diagnostics.ProcessStartInfo proc = new System.Diagnostics.ProcessStartInfo(); proc.FileName = "build"; proc.WorkingDirectory = path; proc.Arguments = args; proc.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal; //proc.CreateNoWindow = true; System.Diagnostics.Process process = System.Diagnostics.Process.Start(proc); process.WaitForExit(1000); but unity write this in console: Win32Exception: Cannot find the specified file System.Diagnostics.Process.StartWithShellExecuteEx (System.Diagnostics.ProcessStartInfo startInfo) (at <ae22a4e8f83c41d69684ae7f557133d9>:0) System.Diagnostics.Process.Start () (at <ae22a4e8f83c41d69684ae7f557133d9>:0) (wrapper remoting-invoke-with-check) System.Diagnostics.Process.Start() System.Diagnostics.Process.Start (System.Diagnostics.ProcessStartInfo startInfo) (at <ae22a4e8f83c41d69684ae7f557133d9>:0) the path is correct... thanks
proc.FileName needs to be either an absolute path or a relative path from the working directory of your Unity game.. which is... I have no idea what but you can print it out with Directory.GetCurrentDirectory(). path will just be the working directory of the new process when it starts. Also, if "build" is a bash script, what you probably really want to be doing is starting the "bash" process and passing the script into it.
now the call build.sh works, but the gulp call don't works... any idea? I see the echo logs... this is the calls: Code (JavaScript): if test "$1" == "smallthing" then echo 'smallthing mode start' es-check es5 './project/data/src/game/js/*.js' './project/data/src/game/js/vendors/*.js' './project/data/src/game/js/states/*.js' gulp --gulpfile gulpfile-smallthing.js echo 'smallthing mode end' fi
I seem to remember at some stage that processes spawned from Unity use the SSL trust chain from Unity, and this would fail for a whole bunch of sites that didn't trust that section of the chain. Disclaimer: I am not a Networking Guy and merely have a vague memory of this problem. You might want to set up a proxy and see if the secure connection is happy or not, or see how it is different if started from within Unity vs from your own bash prompt.