- Home /
How to use Process.Start() with arguments on OSX in an EditorWindow?
Process.Start works great on windows, and very simply as well. But it seems a bit funkier on OSX.
I got it working to just launch an application normally. But I cannot figure out how to get it to launch an application with arguments on OSX. More specifically I am trying to launch a command line application with arguments. How do I do that??
I've already tried this: Process p = System.Diagnostics.Process.Start(new ProcessStartInfo(info.FullName, " -fOGLPVRTC4 -q5 -pvrtciterations8 -i" + filePaths[i] + " -o" + filePaths[i]) { UseShellExecute = false });
it throws a win32 exception
I found the tip to add '{ UseShellExecute = false }' as I did there on some other mono mac forum. So I put it in there, if you leave that line out however it does nothing.
Answer by gamesbyangelina · Jun 24, 2013 at 01:52 AM
This is an old question but comes up prominently in Google. I want to offer an answer! I was trying to execute a command which aliased to another binary somewhere in my Mac. What I ended up doing was explicitly writing in the path to the binary. i.e. instead of:
Process p = new Process();
p.StartInfo.FileName="inkscape";
We have:
Process p = new Process();
p.StartInfo.FileName="/Applications/Inkscape.app/Contents/Resources/bin/inkscape";
I hope this helps some people as this was driving me nuts.
It works but doesn't seem to work with processes outside Applications folder, probably due to user permissions.
i've tried calling openDiff without success, it's a symbolic link to xcrun which is inside /usr/bin.
Answer by Inhuman Games · Feb 06, 2014 at 10:23 AM
Did you try inserting "--args " at the beginning of your arguments string? This solved the issue for me.
Answer by DanDixon · Sep 22, 2011 at 09:27 PM
This may not be helpful, but you could try this method to add arguments and set properties:
Process p = new Process();
p.StartInfo.FileName=command;
p.StartInfo.Arguments = arguments;
p.StartInfo.RedirectStandardError=true;
p.StartInfo.RedirectStandardOutput=true;
p.StartInfo.CreateNoWindow=true;
p.StartInfo.WorkingDirectory=Application.dataPath+"/..";
p.StartInfo.UseShellExecute=false;
p.Start();
I had problems getting Process to work at all until I used this method.
Note that not all of that is required. This works too:
Process p = new Process();
p.StartInfo.FileName=command;
p.Start();
And at the top of the cs file, add this:
using System.Diagnostics;
As discovered in this Unity forum thread about System.Diagnostics.Process.
I Can't get this to work on OSX, it doesn't throw an error just does nothing. Any reason that might be?
Answer by robertono · Jan 11, 2016 at 03:29 PM
Guys, I have been able to launch .app using Process.Start with UseShellExecute=TRUE, and not only from Applications folder. Specifficaly in inside my app: MyApp.app/Contents/Resources/ProcessStart.app
I don't know how it was before, but in Unity 5 it works great!