Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Run unix executable file from Unity

Discussion in 'Scripting' started by cecarlsen, Feb 3, 2010.

  1. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    870
    Dear forum

    I have a unix executable file that I need to run from Unity. I also need to pass it arguments. Is this possible?

    Best
    ~ce
     
  2. Lucas Meijer_old

    Lucas Meijer_old

    Joined:
    Apr 5, 2008
    Posts:
    436
    You can use the .net class Process

    Code (csharp):
    1.  
    2. Process process = new Process();
    3. process.StartInfo.FileName=command;
    4. process.StartInfo.Arguments = arguments;           
    5. process.StartInfo.RedirectStandardError=true;
    6. process.StartInfo.RedirectStandardOutput=true;
    7. process.StartInfo.CreateNoWindow=true;
    8. process.StartInfo.WorkingDirectory=Application.dataPath+"/..";
    9. process.StartInfo.UseShellExecute=false;
    10. process.Start();
    11.  
    You can find details of the usage on msdn: http://msdn.microsoft.com/en-us/library/system.diagnostics.process(VS.71).aspx

    This doesn't work in the webplayer.

    Bye, Lucas
     
  3. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    870
    Thanks Lucas, that is just what I needed.
    ~ce
     
  4. SnowflakePillow

    SnowflakePillow

    Joined:
    Mar 18, 2010
    Posts:
    14
    Code (csharp):
    1. function OnTriggerEnter  (other : Collider) {
    2. Process note = new Process();
    3. note.StartInfo.Arguments = Application.dataPath+"/test.txt";
    4. note.Start(notepad.exe);
    5. }
    This just says a semicolon is missing for me.

    This launches notepad, though:


    Code (csharp):
    1. function OnTriggerEnter  (other : Collider) {
    2. System.Diagnostics.Process.Start("notepad.exe");
    3. }
     
  5. SnowflakePillow

    SnowflakePillow

    Joined:
    Mar 18, 2010
    Posts:
    14
    I guess I am instantiating it incorrectly
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You're trying to use C# syntax in Javascript.

    Code (csharp):
    1. var note = new Process();
    --Eric
     
  7. emergki

    emergki

    Joined:
    Oct 15, 2007
    Posts:
    422
    How can I write a text file with the data from my game in Unity, and, after write the file, make Unity Open the Notepad.exe with the file? (Is something like a report system that I'll need to print, because this I want to work with notepad).


    Can be Done in JavaScript or only in C#? Can you help me?