Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more..
    Dismiss Notice
  3. Dismiss Notice

Shell script / Calling external applications

Discussion in 'Scripting' started by albatross, Nov 16, 2010.

  1. albatross

    albatross

    Joined:
    Sep 16, 2010
    Posts:
    15
    Hello,

    Is there any way to get the Unity script to call a shell script either directly or via a plugin?
    Is there any way to have Unity launch an external application?

    Thanks
     
  2. JRavey

    JRavey

    Joined:
    May 12, 2009
    Posts:
    2,377
    Code (csharp):
    1.  
    2. Process myProc = new Process();
    3. myProc.StartInfo.FileName = "/Applications/Safari.app/Contents/MacOS/Safari";
    4. myProc.Start();
    5.  
    That will start Safari on OSX. The basic layout is the same regardless of platform. If you want it to open a URL, just have it list the URL.

    Code (csharp):
    1.  
    2. Process myProc = new Process();
    3. myProc.StartInfo.FileName = "http://www.unity3d.com";
    4. myProc.Start();
    5.  
    In the second example, it will be handled in accordance with the system's configuration, which should use the default browser.
     
  3. albatross

    albatross

    Joined:
    Sep 16, 2010
    Posts:
    15
    Awesome! I can feel the power
     
  4. Fehr

    Fehr

    Joined:
    Mar 3, 2011
    Posts:
    23
    This seems pretty awesome!

    Just make sure you're using System.Diagnostics before running this command, and if doing so, remove or unambiguously use Debug.Log.
     
    Last edited: Apr 24, 2012
  5. UnityCoder

    UnityCoder

    Joined:
    Dec 8, 2011
    Posts:
    534
    You can also do like this:

    System.Diagnostics.Process.Start("http://www.google.co.in");