使用C#在Mac上启动外部进程 [英] Start an external process on mac with c#
问题描述
我已成功使用System.Diagnostics.Process.Start()在Windows上启动我的外部mono可执行文件.但是,在Mac上失败.我没有收到任何错误,根本什么也没发生.
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.
谢谢!
推荐答案
您需要做的是使用实际可执行文件的完整路径.在OSX上,应用"实际上是具有.app
扩展名的特殊结构的文件夹,并且可执行文件(通常)位于Content/MacOS/[name]
下.
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 under Content/MacOS/[name]
.
例如,打开终端:
System.Diagnosticts.Process.Start("/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal");
或对于TextEdit:
Or for Text
System.Diagnostics.Process.Start("/Applications/TextEdit.app/Contents/MacOS/TextEdit");
要找到可执行文件,可以右键单击(或按住Control键单击)一个应用程序,然后选择 Show Package Contents (显示包内容),这将在Finder中打开实际文件夹.然后,您可以导航到Contents/MacOS
文件夹以找到实际的可执行文件.
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.
要运行 Mono 可执行文件,必须使用Mono可执行文件的完整路径,并将程序作为参数传递.通常情况下,它会类似于/usr/local/bin/mono
或可能的/usr/bin/mono
.
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
.
例如:
System.Diagnostics.Process.Start("/usr/bin/local/mono /Users/Ilya/Projects/SomeApp.exe");
很显然,您将使用.exe
文件的实际路径,以上仅是示例.
Obviously you'd use the actual path to your .exe
file, the above is just an example.
这篇关于使用C#在Mac上启动外部进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!