x


Running an external EXE file from Unity

Dear community,

I am willing to run an external EXE file with command arguments. The Scripting API didn't provide me with information regarding http://System.IO or running external files. The best info received was a link to MS Framework related classes, but I am actually looking for a straightforward example.

I have searched UnityAnswers for some time about this, and the closest example I have found on UnityAnswers is this:

String path = @"f:\temp\data.txt";
Process foo = new Process();
foo.StartInfo.FileName = "Notepad.exe";
foo.StartInfo.Arguments = path;
foo.Start();

I do not use C# for my project but use Javascript instead. Process isn't recognized there.

Please, can you supply me with an example of how to run an external program like "../VideoPlayer/myVideoPlayer.exe -fullscreen" for instance?

more ▼

asked May 05 '10 at 08:38 AM

Christophe F gravatar image

Christophe F
229 9 9 20

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Process is in the System.Diagnostics namespace - you'll need to have import System.Diagnostics at the top of your script to be able to use it like you're doing

Alternatively (though less preferable), you could use System.Diagnostics.Process instead

more ▼

answered May 05 '10 at 10:52 AM

Mike 3 gravatar image

Mike 3
30.5k 10 65 253

Thanks a great lot. I feel quite ashamed by how simple my problem was ; thanks again for your help in revealing where was my mistake.

Here is the full code:

(At start of script)

import System.Diagnostics;

(where you want it to happen :)

var stringPath = "../"; var myProcess = new Process(); myProcess.StartInfo.FileName = "Notepad.exe"; myProcess.StartInfo.Arguments = stringPath; myProcess.Start();

Will update if other problems are met.

May 05 '10 at 11:06 AM Christophe F

Hi Christopher,

There is nothing to be ashamed of. Rest assured that what you posted will be and has been helpful to others. I am one of those receipents.

Nov 16 '11 at 04:03 AM ferraribeng

Would you believe it - this is still helping people. Myself included. Thanks!

Jun 28 '12 at 02:42 PM ActionScripter

This is even helping to help, the community thank you!

Aug 05 '12 at 07:28 PM RodrigoSeVeN
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3465
x111
x28

asked: May 05 '10 at 08:38 AM

Seen: 6024 times

Last Updated: Aug 05 '12 at 07:28 PM