tags:

views:

101

answers:

4

Hi,

I have a c program which I can launch at command prompt. Is it possible for me the lunch this application in my another c program? If yes, how? All the google result shows me how to do that using pthread? Will that work? I suspect that I need a new process for my c program.

Thank you.

+3  A: 

It is system specific, but there is commonly execve or something like that and there is always system("/path/to/program"); that you can use that is also system specific

Earlz
Keep in mind that `system()` forks *twice* – Its argument is passed to the shell/command interpreter.
Bertrand Marron
+3  A: 

Have you looked into using fork() and exec()? Fork will split a process, exec lets you start a new program from one of the instanaces that was fork'd.

First hit on google:

http://www.yolinux.com/TUTORIALS/ForkExecProcesses.html

As others have mentioned, the details may vary depending on what OS you are using.

FrustratedWithFormsDesigner
A: 

In addition to an explicit fork/exec and system, there is popen. (All in a unixish environment).

You'll get better help if you are more explicit about what your operating environment is and how you need to interact with the daughter process.

dmckee
A: 

The CreateProcess function is the way to go in Windows.

You can use the system() function to literally make commands against the console, but I don't remember if it blocks or not.

For linux look into execv. This page has a linux parent launching a child application example in linux include a communications pipe between the two..

Also, execve will launch by executable filename.

Präriewolf