How to launch a c program from another c program
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.
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
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.
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.
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.
精彩评论