Start an external process on mac with c#

14,734

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.

Share:
14,734
Ilya Suzdalnitski
Author by

Ilya Suzdalnitski

Full-stack engineer with a focus on delivering reliable and maintainable software. I have a strong preference for functional programming and believe that it is the most important aspect of producing quality software. Passionate about continuous improvement, and always eager to learn and apply new technology.

Updated on June 24, 2022

Comments

  • Ilya Suzdalnitski
    Ilya Suzdalnitski almost 2 years

    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!

  • Martin Baulig
    Martin Baulig about 11 years
    On OS X, it should actually be /Libraries/Frameworks/Mono.framework/Versions/Current/bin/mo‌​no - btw. IMHO, instead of posting a separate answer you should propose an edit for things like this, where you're only adding stuff to an existing answer.
  • rossipedia
    rossipedia about 11 years
    This is a good point. I would strongly suggest the which mono approach if this is a user application. If its a server side, then you might want to make the path to mono a configuration setting.
  • LubosD
    LubosD almost 10 years
    One important note: the target EXE file needs an executable bit set, or Mono will refuse the launch that program.
  • Carlos Borges
    Carlos Borges about 4 years
    If you want to open a html page with chrome, how do you do that? I have tried System.Diagnostics.Process.Start("/Applications/Google Chrome.app/Contents/MacOS/Google Chrome SubDB.html"); but this not work.
  • DJ001
    DJ001 over 3 years
    If chrome is your default browser, then simply Process.Start(path/to/html/file) should work