OSX equivalent of ShellExecute?

前端 未结 3 1738
北荒
北荒 2020-12-06 12:09

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 ShellExec

3条回答
  •  执念已碎
    2020-12-06 12:20

    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());
    

提交回复
热议问题