开发者

Running executable in C code [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜