const char *programname = "/usr/local/bin/node";
const char **nargv = new const char* [5];//extra room for program name and sentinel
nargv [0] = programname; // by convention is program name
nargv [1] = "/folder/convert-json.js"; // arg 1 to node
nargv [2] = "/folder/723edc747c39.json"; // arg 2
nargv [3] = "/tmp/data.json"; // arg 3
nargv [4] = NULL; // end of arguments sentinel is NULL
pid_t pid = fork();
if (pid == 0) /* child */ {
if (execv(programname, (char **)nargv) == -1) {
/* Handle error */
std::cout << "!! an error in calling node\n";
}
_exit(1); /* in case execv() fails */
}
Я построил на твоем (@ Джош-Олсон). Этот код работает, надеюсь, он помогает другим.