OSX相当于ShellExecute? [英] OSX equivalent of ShellExecute?

查看:182
本文介绍了OSX相当于ShellExecute?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C ++应用程序,我从Win32移植到OSX。我想要能够启动任意文件,就像用户打开它们。这在使用ShellExecute的Windows上很容易。我如何在Mac上完成同样的事情?



谢谢!

解决方案

> system(); 在任何C ++应用程序中。在OSX上,您可以使用打开命令启动内容,如同



在打开的文档中:

命令打开文件(或目录或URL),就像您已双击文件的图标一样。如果未指定应用程序名称,则通过LaunchServices确定的默认应用程序用于打开指定的文件。


看起来像:

  string command =open+ filePath; 
system(command.c_str());


I've got a C++ app that I'm porting from Win32 to OSX. I'd like to be able to launch arbitrary files as if the user opened them. This is easy on windows using ShellExecute. How do I accomplish the same thing on the Mac?

Thanks!

解决方案

You can call system(); in any C++ application. On OSX, you can use the open command to launch things as if they were clicked on.

From the documentation for open:

The open command opens a file (or a directory or URL), just as if you had double-clicked the file's icon. If no application name is specified, the default application as determined via LaunchServices is used to open the specified files.

All together, it would look like:

string command = "open " + filePath;
system(command.c_str());

这篇关于OSX相当于ShellExecute?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆