Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start an external process on mac with c#

I'm successfully using System.Diagnostics.Process.Start() to start my external mono executable on windows. However it fails on mac. I'm not getting any error, simply nothing at all happens.

I tried doing it the following way:

System.Diagnostics.Process.Start("mono", "/path/program.exe");

Also I've tried opening terminal like the following (which also failed):

System.Diagnostics.Process.Start("Terminal");

The only thing I was able to do is launch the Terminal in the following way:

System.Diagnostics.Process.Start("open", "-a Terminal");

Any ideas? I would really appreciate any help.

Thanks!

like image 205
Ilya Suzdalnitski Avatar asked Mar 16 '13 17:03

Ilya Suzdalnitski


People also ask

How do I run a program in Mac terminal?

In the Terminal app on your Mac, enter the complete pathname of the tool's executable file, followed by any needed arguments, then press Return.

How do I start a process in VB net?

Start another application using your . NET code As a . NET method, Start has a series of overloads, which are different sets of parameters that determine exactly what the method does. The overloads let you specify just about any set of parameters that you might want to pass to another process when it starts.

What is process start?

Start(ProcessStartInfo) Starts the process resource that is specified by the parameter containing process start information (for example, the file name of the process to start) and associates the resource with a new Process component. Start()


1 Answers

What you need to do is use the full path to the actual executable file. On OSX, the "apps" are actually specially structured folders with a .app extension, and the executable (generally) lives under Content/MacOS/[name].

For example, to open the Terminal:

System.Diagnostics.Process.Start("/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal");

Or for TextEdit:

System.Diagnostics.Process.Start("/Applications/TextEdit.app/Contents/MacOS/TextEdit");

To locate the executable, you can right-click (or control-click) an app, and select Show Package Contents, and that will open up the actual folder in Finder. You can then navigate to the Contents/MacOS folder to find the actual executable.

To run your Mono executables, you have to use the full path to the mono executable and pass your program as an argument. Usually it will be something like /usr/local/bin/mono or possibly /usr/bin/mono.

For example:

System.Diagnostics.Process.Start("/usr/bin/local/mono /Users/Ilya/Projects/SomeApp.exe");

Obviously you'd use the actual path to your .exe file, the above is just an example.

like image 104
rossipedia Avatar answered Oct 06 '22 02:10

rossipedia