Running executable in C code [closed]
I am writing in C (not C++) on a 开发者_开发问答Mac. I want to be able to run a UNIX executable from C, something like this:
#include <some-wacky-header.h>
int main (int argc, char * argv[])
{
int r = some_wacky_executable_run(path_to_my_file_as_char_array);
return 0;
}
NOTE: I don't want to use the system()
command to run the executable.
How about exec()
? It replaces your running program with another one, rather than having both run like system()
does.
popen()
is another option, though I imagine if you don't like system()
(why?), you won't like that either.
I'd suggest using fork()
+ exec()
, since this allows the original process to continue working in parallel. Unless you tell us why you do not want to use system()
, however, there is no way to be sure that this solution would be acceptable for you. popen()
is another alternative, if you need access to the standard input or output of the called executable.
精彩评论