Start an external process on mac with c#

后端 未结 3 443
暖寄归人
暖寄归人 2021-02-06 01:15

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 a

3条回答
  •  鱼传尺愫
    2021-02-06 02:17

    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.

提交回复
热议问题