Search Unity

How to run or remote external program within Unity Editor ?

Discussion in 'Scripting' started by apple_motion, May 11, 2010.

  1. apple_motion

    apple_motion

    Joined:
    Jul 2, 2009
    Posts:
    169
    Hi all,

    I am looking for the way to use Unity as a pre-production tool. Is there anyway to run external program within unity editor ?

    This is my case, I wrote a script for readout the hierarchy of the GameObject and saved as a text file onto the local hard disk, then open it by an Apple OSX program called Graphviz for making hierarchy chart.
    http://www.youtube.com/watch?v=cEDeoFXLOt4
    (Currentlly, I open it manually)

    Is there any command can boot up that application and pass in the text file onto the target program within Unity ?? If yes, I like to create more tool, like linking to imagemagick... etc

    Many Thanks,
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601

    From the editor yes through the .net functionality for that (see MSDN, docs for the System namespace), but not within as part of it.
     
  3. apple_motion

    apple_motion

    Joined:
    Jul 2, 2009
    Posts:
    169
    Although I can't found anything from MSDN (as usual), but thank you so much for telling me the right direction :)

    I found this somewhere and its seem to work for me :)
    Code (csharp):
    1. import System.Diagnostics;
    2.  
    3. var path:String = "somewhere";
    4. var foo:Process = new Process();
    5. function Start()
    6. {  
    7.     foo.StartInfo.FileName = "someprogram";
    8.     foo.StartInfo.Arguments = path;
    9.     foo.Start();
    10. }
     
  4. ilikegame

    ilikegame

    Joined:
    Apr 15, 2010
    Posts:
    8
    Code (csharp):
    1. import System.Diagnostics;
    2.  
    3. var path:String = "somewhere";
    4. var foo:Process = new Process();
    5. function Start()
    6. {  
    7.     foo.StartInfo.FileName = "someprogram";
    8.     foo.StartInfo.Arguments = path;
    9.     foo.Start();
    10. }
    Um, Hi, I'm really new to unity and I'm interested in running external programs as well... and how... do I use this exactly?
     
  5. apple_motion

    apple_motion

    Joined:
    Jul 2, 2009
    Posts:
    169
  6. davebuchhofer

    davebuchhofer

    Joined:
    Nov 9, 2007
    Posts:
    126
  7. apple_motion

    apple_motion

    Joined:
    Jul 2, 2009
    Posts:
    169
    Many Thanks ! It is work on OSX now !!

    Code (csharp):
    1. import System.IO;
    2.  
    3. function Start()
    4. {
    5.     var info:FileInfo = new FileInfo("/Applications/TextEdit.app/Contents/MacOS/TextEdit");
    6.     System.Diagnostics.Process.Start(info.FullName);
    7. }
     
  8. ilikegame

    ilikegame

    Joined:
    Apr 15, 2010
    Posts:
    8
    Code (csharp):
    1.  
    2. import System.Diagnostics;
    3.  
    4.  
    5. var fileLocation: String = "C:/Program Files/Skype/Phone/Skype.exe";
    6. var test:Process = new Process();
    7. test.StartInfo.FileName = fileLocation;
    8. function Start()
    9. {
    10.  
    11. test.Start();
    12. UnityEngine.Debug.Log("we got here!");
    13. }
    14.  
    This one works (for windows), too But I have some question here - when I build it into web player version, it doesn't work anymore. Can anyone come up with this idea?
     
    Jamado_ likes this.
  9. apple_motion

    apple_motion

    Joined:
    Jul 2, 2009
    Posts:
    169
    Never works ! It is the security reason. The web-player can't access the local IO. In fact, that is very danger, if allowed. I may remote any computer in this planet to do something... :p
     
  10. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    The webplayer can not access anything related to the local system:

    No system.io.file stuff, no file:// protocol, no System.Environment, no System.Diagnostics

    You can communicate to the outer world only through requestes to the web and that will be done through the browsers networking
     
  11. HolBol

    HolBol

    Joined:
    Feb 9, 2010
    Posts:
    2,887
    Lol, I'm necroposting again, but would this work in a Windows Standalone? It might be just what I need.
     
  12. HolBol

    HolBol

    Joined:
    Feb 9, 2010
    Posts:
    2,887
    Dw, sorted. IT'S PERFECT!

    Now with some money, my game console can go ahead, and all because of this line of code :D
     
  13. lmbarns

    lmbarns

    Joined:
    Jul 14, 2011
    Posts:
    1,628
    Wow this is amazing. I can load macro files from autohotkey (compiled to .exe) with Unity......allowing imagesearch(), pixelsearch() functions, controlling the mouse position and simulating inputs, along with dialogue/tooltips independent of Unity that overlay the game window. Probably useful for simulators. Or instructional GUI's...

    When you load unity it loads the script, when the script loads it checks for the unity window and focuses on it. You can scan for pixels or images, move the mouse to it, send various input from the keyboard/mouse or custom scripts even tie into mysql etc.
     
  14. MrSKYone

    MrSKYone

    Joined:
    Sep 25, 2012
    Posts:
    3
    Hi,

    I did make this work on OSX but it doesn't want to work if I want to open the Terminal. Does it requires another extension name such as .app ? If you have any idea please tell me :) Thanks a lot!
     
  15. ashokbugude

    ashokbugude

    Joined:
    Feb 10, 2016
    Posts:
    20
    I am trying to start a process in Linux using below c# code in mono developer for Unity in start function.

    Process.start(filepath);

    Results as checked in task manager of linux
    1. Process starts but ends in 3 secs with Memory shown as 'N/A' in task manager during the 3 secs and Status as 'Zombie'

    Note : The process works fine when executed from terminal or when double clicked or when run in Unity independent C# project
     
  16. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    298
    Hey there! Did you ever get this to work and open a Terminal window? I've run into the same issue. It works behind the scenes, but I don't know its progress etc.
     
  17. lhaugh

    lhaugh

    Joined:
    May 12, 2013
    Posts:
    1
    I got it working with:

    Code (CSharp):
    1. ProcessStartInfo startInfo = new ProcessStartInfo() {
    2.                 FileName = "bash",
    3.                 UseShellExecute = false,
    4.                 RedirectStandardError = true,
    5.                 RedirectStandardInput = true,
    6.                 RedirectStandardOutput = true,
    7.                 CreateNoWindow = true,
    8.                 Arguments = " -c \"" + command + " \""
    9.             };
     
    unity_KUYdzwHIrEhNuQ likes this.
  18. unity_KUYdzwHIrEhNuQ

    unity_KUYdzwHIrEhNuQ

    Joined:
    Jul 15, 2019
    Posts:
    1
    You my friend have solved my week long head ache trying to lauch VS Code on mac through my editor tools
     
  19. Scott-Steffes

    Scott-Steffes

    Joined:
    Dec 31, 2013
    Posts:
    59
  20. talespinvr

    talespinvr

    Joined:
    Apr 11, 2020
    Posts:
    7
    Is there a way to do this during play mode? My thread keeps getting aborted, likely by Unity.