NSHPOPEN(3) UNIX Programmer's Manual NSHPOPEN(3) NAME nshpopen, nshpclose - initiate I/O to/from a process SYNOPSIS #include FILE *nshpopen(command, type) char *command, *type; nshpclose(stream) FILE *stream; DESCRIPTION The arguments to _n_s_h_p_o_p_e_n are pointers to null-terminated strings containing respectively a shell command line and an I/O mode, either "r" for reading or "w" for writing. It creates a pipe between the calling process and the command to be executed. The value returned is a stream pointer that can be used (as appropriate) to write to the standard input of the command or read from its standard output. A stream opened by _n_s_h_p_o_p_e_n should be closed by _n_s_h_p_c_l_o_s_e, which waits for the associated process to terminate and returns the exit status of the command. Because open files are shared, a type "r" command may be used as an input filter, and a type "w" as an output filter. _N_s_h_p_o_p_e_n breaks up the _c_o_m_m_a_n_d argument string at spaces and tabs for the child process. However, it does not invoke a shell, and does not attempt any shell shell meta character parsing. In particular, quoted white space will still cause argument seperation. By avoiding calling a shell, pipe creation is a great deal quicker. Also, by avoiding the (rather complicated) shell meta character parsing, some types of bugs may be avoided. This is important where the security of setuid programs is involved. SEE ALSO pipe(2), popen(3), fopen(3S), fclose(3S), system(3), wait(2), sh(1) DIAGNOSTICS _N_s_h_p_o_p_e_n returns a null pointer if files or processes cannot be created, or the shell cannot be accessed. _N_s_h_p_c_l_o_s_e returns -1 if _s_t_r_e_a_m is not associated with an `nshpopened' command. BUGS Buffered reading before opening an input filter may leave the standard input of that filter mispositioned. Similar Printed 5/16/88 local 1 NSHPOPEN(3) UNIX Programmer's Manual NSHPOPEN(3) problems with an output filter may be forestalled by careful buffer flushing, for instance, with _f_f_l_u_s_h, see _f_c_l_o_s_e(3). _N_s_h_p_o_p_e_n does not call a shell to do it's work. It does not attempt to process shell meta characters. Thus, it does not treat quotes, I/O redirects, or file name wildcard charac- ters specially. This is it's incompatibility with _p_o_p_e_n(_3). This type of function should have been included with _p_o_p_e_n(_3) in the standard I/O library. Printed 5/16/88 local 2