- Home /
Launch a python script from a javascript file
Hello, i just need a simple way to launch a python interpreter (which will run some simple I/O functions in the background) at the start of my game. Cannot find this anywhere on the internets.
I'm using it grab some sensor values to pass to unity, but its not really a smooth operation to have to manually start the interpreter from a terminal window.
Thanks!
What are your "sensor values"? Are you running Unity with some interesting custom hardware? (just curious ...)
Answer by yoyo · Mar 10, 2011 at 05:28 AM
You can launch an external process like this (Javascript or C#) ...
System.Diagnostics.Process.Start("python.exe", "boaconstrictor.py");
For more information (there are lots of options), see the MSDN docs. You can redirect and capture standard output and standard error, pass in more options, wait for the process to complete, etc.
Note that if this is for other people to use you will need to ensure python is available on their system -- this will work best in the Unity editor environment, or should be ok from a standalone build but I would be very surprised if it worked from a web player (and an iPhone is right out! ;-)
sorry, forgot to mention im working on OSX. I couldn't get this to work, i did remove the .exe extension. Also, im not very sure where to check whether the process has actually started. Im new to this aspect of program$$anonymous$$g.
im trying to pass some simple values from soft switches sewn into an outfit, that will control an avatar in-game, plus a photocell to regulate environmental light.
Thanks!
It ought to work cross-platform, but I'm on Windows, so no guarantees. Try getting it to launch something simple you know should work -- I tested by launching notepad.exe, the little text editor that comes with Windows.
P.S. Once you know you can launch an external process, look at the $$anonymous$$SDN docs to see how to capture standard output, then you can send it to Unity's Debug.Log to see what's happening.
Your answer
Follow this Question
Related Questions
Launch a Python Interpreter from Unity [Javascript] 0 Answers
How can I Javascript a phone call from within Unity? 1 Answer
Programming language C# learning resource 2 Answers
Call SoundManager with JS? 0 Answers
Calling Functions from another Script 3 Answers