Start an external process on mac with c#(使用 c# 在 mac 上启动外部进程)
问题描述
我已成功使用 System.Diagnostics.Process.Start() 在 Windows 上启动我的外部单声道可执行文件.但是它在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.
我尝试了以下方式:
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 (generally) lives under Content/MacOS/[name].
例如,打开终端:
System.Diagnostics.Process.Start("/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal");
或者对于文本
System.Diagnostics.Process.Start("/Applications/TextEdit.app/Contents/MacOS/TextEdit");
要找到可执行文件,您可以右键单击(或按住 Control 单击)应用程序,然后选择 显示包内容,这将在 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 上启动外部进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 c# 在 mac 上启动外部进程
基础教程推荐
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
