I am trying to write a program that runs an external program.
I know that I can catch stdout, and I can catch stdout and stderr together BUT the question is can I catch the stderr and stdout separated?
I mean for example, stderr in varaible STDERR and stdout in variable STDOUT.
Also I need the exit code of the external program.
int pid = fork();
if (pid == 0)
// to be truly correct, you should also close all other inherited descriptors child doesn't need
if (pid < 0)
// failure, close the other ends of pipes
// here you can write to in_pipe and read from out_pipe and err_pipe to communicate with the child process
// remember to call waitpid when you finish