Answer the question
In order to leave comments, you need to log in
How to duplicate output to file?
There is a command processor in the C language under Linux, which can execute both its own built-in commands and execute external commands and programs. It is required to duplicate the output of stderr and stdout into two different files (the output of both external commands and programs that are created via fork(), and your own). I suspect that it is necessary to use the tee () function, but I did not find examples of its work.
UPD:
For my child process, the output is as follows:
int pipefd[2];
...
pid_t childId = fork();
case 0:
trap_signal(SIGTTOU, SIG_DFL);
trap_signal(SIGTTIN, SIG_DFL);
trap_signal(SIGCHLD, SIG_DFL);
if(!background && !convey)
tcsetpgrp(cterm, getpid());
setpgid(0, 0);
if (isWriter) close(pipefd[0]);
if (isReader!=-1) {
close(0);
dup(oldChannelOut);
}
if(isWriter){
close(1);
dup(pipefd[1]);
}
Answer the question
In order to leave comments, you need to log in
Wow! New challenge though. I didn't know... Here is a description with an example man7.org/linux/man-pages/man2/tee.2.html
We used to pervert with manual copying in 2.4.xx kernels :-)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question