Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!cec2!news From: flan@cics.Berkeley.EDU (Ian Flanigan) Newsgroups: comp.unix.questions Subject: Odd ouput redirection in background script Keywords: Odd, strange, wierd, csh, shell, background, script Message-ID: <1991Feb4.211315.13175@cec1.wustl.edu> Date: 4 Feb 91 21:13:15 GMT Sender: news@cec1.wustl.edu (USENET News System) Reply-To: flan@cics.Berkeley.EDU (Ian Flanigan) Organization: Center for Intelligent Computing Systems Lines: 59 Today I was cooking up a small program to save me the trouble of having to wait for my rsh's to finish: /* Background Processes */ #include main(argc, argv) int argc; char *argv[]; { if (fork()) exit(0); execvp(argv[0],&argv[1]); printf("OOps\n"); } I used the following script to give it a test: #!/bin/csh ls > /tmp/tt$$ Then I typed, "background test_scr" to give it a test and it worked fine; I got the output in the file in /tmp and everything. I then tried to use it with rsh and it was a complete failure. Right away I remebered that the child process inherits everything, so I needed to close stdin and stdout. So the program became: /* Background Processes */ #include main(argc, argv) int argc; char *argv[]; { if (fork()) exit(0); close(0); close(1); execvp(argv[0],&argv[1]); printf("OOps\n"); } Easy. Now I gave it a test with, "background test_scr" and it wrote the directory listing to my screen. My question: Why? Not only did I close stdout, but I also had it re-directed in the script. Is it a probelem with the shell? I've gotten the program to work the way I want it to, now, but I am baffled by the odd behavior. Thanks for any info. -- Ian Flanigan flan@cics.wustl.edu "You can never have too many napkins." wucs1.wustl.edu!cics!flan@uucp