使用 c# 在 mac 上启动外部进程

Start an external process on mac with c#(使用 c# 在 mac 上启动外部进程)
本文介绍了使用 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 上启动外部进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)