-1

I want to open an additional program with c++ on XCode. It is Firefox. But if I make

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

There is an error 'ShellExecute' was not declared in this scope In other forum there was a clue to include windows.h and shellapi.h

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

but that makes other errors

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

What should I do? I want to open frefox with c++ in XCode on Mac?

Korne127
  • 168
  • 14

3 Answers3

1

Try running this in Terminal to open Firefox:

open -a Firefox http://www.ibm.com

If that does what you want, you need to wrap it in system() like this:

#include <cstdlib>
#include <fstream>
#include <iostream>

int main()
{
    std::system("open -a Firefox");
}
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
0

ShellExecute() is only available through the Windows API. You don't have a Windows system.

You can simply use the (more portable) system() function, or one of the exec() functions available on POSIX compliant systems.

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
  • If I make `system()` only comes `sh: file://localhost/Applications/Firefox.app: No such file or directory ` But Firefox doesn't open! – Korne127 Jul 21 '16 at 13:53
  • You'll need that file to be an executable of course. If you want to start a local app, start firefox parameterized with that path. – πάντα ῥεῖ Jul 21 '16 at 13:55
  • I have given a false file link, it was `/Applications/Firefox.app:` but then only comes `sh: /Applications/Firefox.app: is a directory` and firefox doesn't open – Korne127 Jul 21 '16 at 13:58
  • @Korne127 Think it over. How would you start firefox opening that app from a command line terminal? This is what you need to specify as `system()`'s parameter. – πάντα ῥεῖ Jul 21 '16 at 14:20
0

I tried the same with chrome and I had to set it in inverted commas:

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


    return 0;
}

with the apostrophe it worked!

Schoko98
  • 1
  • 1