在Mac上用c ++打开一个额外的程序[XCode]

时间:2016-07-21 13:17:53

标签: c++ xcode macos shellexecute

我想在XCode上用c ++打开一个额外的程序。 这是Firefox。 但是如果我做了

Shell Execute("file://localhost/Applications/Firefox.app"); 

发生错误'ShellExecute' was not declared in this scope 在其他论坛中,有一个线索包括windows.h和shellapi.h

#include <shellapi.h>
#include <windows.h>

但这会产生其他错误

shellapi.h: No such file or directory
windows.h: No such file or directory

我该怎么办?我想在Mac上的XCode中使用c ++打开frefox吗?

3 个答案:

答案 0 :(得分:0)

ShellExecute()仅可通过Windows API获得。你没有Windows系统。

您可以简单地使用(更便携式)system()函数或POSIX兼容系统上可用的exec()函数之一。

答案 1 :(得分:0)

尝试在终端中运行此功能以打开Firefox:

wp_get_object_terms

如果这样做你想要的,你需要将它包装在open -a Firefox http://www.ibm.com 中,如下所示:

system()

答案 2 :(得分:0)

我尝试使用chrome进行相同操作,但必须将其设置为反逗号:

int main() {
    system("open -a 'Google Chrome'");


    return 0;
}

用撇号有效!