Search Unity

HELP! bash command

Discussion in 'Scripting' started by lordubik, Apr 22, 2020.

  1. lordubik

    lordubik

    Joined:
    Feb 18, 2013
    Posts:
    149
    Hi all!
    Is there a way to run a bash script (with args) from C# inside unity?

    Many thanks for help!

    Stefano
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    Last edited: Apr 22, 2020
  3. lordubik

    lordubik

    Joined:
    Feb 18, 2013
    Posts:
    149
    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: :confused:

    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... :oops:


    thanks
     
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    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.
     
  5. lordubik

    lordubik

    Joined:
    Feb 18, 2013
    Posts:
    149
    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):
    1.  
    2. if test "$1" == "smallthing"
    3. then
    4. echo 'smallthing mode start'
    5. es-check es5 './project/data/src/game/js/*.js' './project/data/src/game/js/vendors/*.js' './project/data/src/game/js/states/*.js'
    6. gulp --gulpfile gulpfile-smallthing.js
    7. echo 'smallthing mode end'
    8. fi
     
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,736
    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.
     
    PraetorBlue likes this.