-2

I would like to know if there is a way to launch an application through a c++ code? As if I was launching it through the command line (with giving parameters for example).

If it exists, please can you provide me with both the windows code as well as linux code (in case they differ).

Cœur
  • 37,241
  • 25
  • 195
  • 267
RyanLK
  • 13
  • 1
  • 1
    Yes. You can either use `system` for a synchronous call, or `fork` and ` exec` for spawning a concurrent child process, or `popen` for short-lived child processes. All of those approaches are somewhat subtle and require a bit of care and thought. – Kerrek SB Mar 09 '16 at 10:44

2 Answers2

1

You can use system calls, like:

  1. exec()
  2. fork()

You can find plenty of examples. I had also answered a question about fork() here.

For exec(), you could read this: Please explain exec() function and its family.

Community
  • 1
  • 1
gsamaras
  • 71,951
  • 46
  • 188
  • 305
  • Okay thanks a lot. I have not tried it yet, but does the parameter that exec() uses is a path to the application I want to launch? – RyanLK Mar 09 '16 at 10:54
  • Okay the documentation actually answers that, thank you. – RyanLK Mar 09 '16 at 10:57
  • You are welcome @RyanLK. I updated my answer! Yes, pretty much that's it, see the examples here: http://pubs.opengroup.org/onlinepubs/009695399/functions/exec.html Also notice that I upvoted your question since you seem new, but I also voted to close as too broad, you need to search more before asking next time. :) Thanks for the upvote! – gsamaras Mar 09 '16 at 10:58
  • I tried to searched but unfortunately I didn't really know how to put it :( so I thought asking directly would be better. Hehe, no worries thx again! – RyanLK Mar 09 '16 at 11:16
  • I see @RyanLK. I do not know if you can do so, but you may want to read this too: http://stackoverflow.com/help/someone-answers – gsamaras Mar 09 '16 at 12:34
0

For Windows, you can use one of the spawn family of functions, like _wspawnl. For Linux, you can use one of the exec family of functions, in combination with fork, like execl.

H. Guijt
  • 3,325
  • 11
  • 16