Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

HELP! bash command

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

  1. lordubik

    lordubik

    Joined:
    Feb 18, 2013
    Posts:
    71
    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:
    2,352
    Last edited: Apr 22, 2020
  3. lordubik

    lordubik

    Joined:
    Feb 18, 2013
    Posts:
    71
    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:
    2,352
    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:
    71
    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:
    7,588
    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.
unityunity