Odd ouput redirection in background script

Paul Falstad pfalstad at phoenix.Princeton.EDU
Wed Feb 6 03:08:08 AEST 1991


flan at cics.Berkeley.EDU (Ian Flanigan) wrote:
>#!/bin/csh
>ls > /tmp/tt$$

>  close(0);
>  close(1);
>  execvp(argv[0],&argv[1]);

>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?

Yes, this is a bug in csh.  You should not call csh with stdin closed;
you should at least assign it to /dev/null.  If you don't, csh will get
the file descriptors confused, so that stdout will become stdin, and stderr
will become stdout.  The output of ls in your case was being written to
stderr.  This is in the csh bug list, which I ftp'ed from I forget
where.

I know you mentioned that you got it working some other way, but you
might want to check out question #12 in the FAQ for more info on how to
get rsh to work the way you want it to.

--
Paul Falstad, pfalstad at phoenix.princeton.edu PLink:HYPNOS GEnie:P.FALSTAD
10 PRINT "PRINCETON CS"          | #include <std.disclaimer.h>
20 GOTO 10                       | I think sexual ecstasy's overrated.



More information about the Comp.unix.questions mailing list