[comp.unix.misc] system cmmand

abmg@cathedral.cerc.wvu.wvnet.edu (Aliasghar Babadi) (04/24/91)

Hi,

	I run a program using the system command similar to the following

           system("prog &");

        for some programs I lose the stdin inputs. For some others get
a lots of stdin input. What am I doing wrong? thanks in advance.

dick@ahds.UUCP (Dick Heijne CCS/TS) (04/24/91)

In article <1628@babcock.cerc.wvu.wvnet.edu>, abmg@cathedral.cerc.wvu.wvnet.edu (Aliasghar Babadi) writes:
> Hi,
> 
> 	I run a program using the system command similar to the following
> 
>            system("prog &");
> 
>         for some programs I lose the stdin inputs. For some others get
> a lots of stdin input. What am I doing wrong? thanks in advance.
See User Manual (SysV): sh(1) or (Xenix): sh(C) approx. pp. 9:

	" If a command is followed by & the default standard input for
	  the command is the empty file /dev/null. Otherwise, the 
	  environment for the execution of a command contains the file
	  descriptors of the invoking shell etc....."

Remember that system(3C) does a "sh -c" to do it's job, so rules apply
to sh(1).
This explains situations where you don't get stdin input at all.
Situations where you get lots(???) of stdin input must be explainable
by the way the argument to system() is formatted.

Dick.