c - How to execute ./process 2>&1 | tee log.txt with execvp -
i try write process controller. should restart process again every time fails. start process following terminal command:
./process 2>&1 | tee log.txt
now want execute command execvp
:
int main() { int status; while(1) { pid = fork(); char* const argv[4] = {"2>&1", "tee", "log.txt", null}; if(pid == 0) { // make child process ./process if(execvp("./process", argv) { perror("execvp"); exit(1); } } else if(pid > 0) { sleep(3); // wait ./process return waitpid(pid, &status, 0); } } }
this example program doesn't fail , ./process starts 2>&1 | tee log.txt
not executed or @ least log file doesn't appear.
any suggestions?
Comments
Post a Comment