Redirect STDOUT and STDERR to socket in C?
问题 I am trying to redirect STDOUT AND STDERR to a socket. I did: if(fork() == 0) { dup2(newsock, STDOUT_FILENO); dup2(newsock, STDERR_FILENO); execvp(); } Somehow, it only showed the first little part of the output. for example, it showed on "mkdir" when I try to execute ls or mkdir. What's the problem? I tried the flollowing it works, but I can only redirect one of STDOUT or STDERR close(1); dup(newsock); Thanks a lot. 回答1: Your use of dup2() looks fine, so the problem is probably elsewhere.