| hamedhmd (3) | |
|
Hi 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. Thanks a lot. | |
|
|
|
| kbw (5522) | |||||
|
You can't do it with csh. Start with this, noise.c:
Build it, then run:
| |||||
|
Last edited on
|
|||||
| hamedhmd (3) | |
|
I don't want to write them into Separate Files and then read from File. I want to catch them directly into my variable. Like the way we read stdout line by line with file descriptor. | |
|
|
|
| rapidcoder (737) | |||
Use fork + execvp. Sketch of solution (not a complete solution - you have to add error checking, includes, declarations):
| |||
|
Last edited on
|
|||
| hamedhmd (3) | |
|
Thanks a lot. Another question!? How can I catch the exit code of program?? Or the PID of the external program!? I know I can read $? but is there another way?? | |
|
Last edited on
|
|
| rapidcoder (737) | |
| Use waitpid. It returns the exit code. Actually you *have* to use it, otherwise the child process becomes a zombie. | |
|
|
|
| ne555 (4386) | |
| or an orphan. | |
|
|
|