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!
To expand on Bryan answer, please do not hardcode the path
/usr/bin/local/
in your code.To find out the correct path in each system, there are various techniques, but I'm not sure which is the best one:
which mono
to locate the full path. For this you would need to callwhich
from another Process instance. (Not sure ifwhich
comes by default in all Mac systems)/Library/Frameworks/Mono.framework/Versions/Current/bin/pkg-config
(like it is done here).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 (usually) lives underContent/MacOS/[name]
.For example, to open Terminal:
Or for 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:
Obviously you'd use the actual path to your
.exe
file, the above is just an example.The little known feature of Mono is that you can directly run the .exe file (to be compatible with how it is done in Windows, but also for the convenience). It is started using the same Mono VM that started the original executable. In other words one can simply do:
Well, at least it works for me on Linux ;)
Edit:
Here's the source for that feature, should work on every platform.