|
|
1.1 ! root 1: .TH POPEN 3S ! 2: .CT 2 comm_proc ! 3: .SH NAME ! 4: popen, ppopen, vepopen, pclose \(mi open a pipe to/from a process ! 5: .SH SYNOPSIS ! 6: .nf ! 7: .B #include <stdio.h> ! 8: .PP ! 9: .B FILE *popen(command, type) ! 10: .B char *command, *type; ! 11: .PP ! 12: .B FILE *ppopen(command, type) ! 13: .B char *command, *type; ! 14: .PP ! 15: .B FILE *vepopen(command, type, args, env) ! 16: .B char *command, *type, **args, **env; ! 17: .PP ! 18: .B int pclose(stream) ! 19: .B FILE *stream; ! 20: .fi ! 21: .SH DESCRIPTION ! 22: The first argument to ! 23: .I popen ! 24: is a pointer to a null-terminated string ! 25: containing a command line for ! 26: .IR sh (1). ! 27: .I Type ! 28: is as in ! 29: .IR fopen (3). ! 30: .I Popen ! 31: creates a pipe between ! 32: the calling process and ! 33: the command and returns ! 34: a stream pointer that ! 35: can be used to write to the standard input ! 36: of the command or to read from the standard output. ! 37: .PP ! 38: .I Ppopen ! 39: uses the ! 40: .B -p ! 41: shell flag to restrict the environment of the shell. ! 42: Both ! 43: .I popen ! 44: and ! 45: .I ppopen ! 46: set the effective userid to the real userid ! 47: before calling the shell. ! 48: .PP ! 49: .I Vepopen ! 50: has arguments akin to those of ! 51: .I execve ! 52: (see ! 53: .IR exec (2)): ! 54: a file to be executed, ! 55: a mode as above, ! 56: a null-terminated vector of argument strings, ! 57: and a null-terminated vector of environment strings. ! 58: The shell is not called, and the effective userid is preserved. ! 59: .PP ! 60: A stream opened by these routines ! 61: should be closed by ! 62: .I pclose, ! 63: which waits for the associated process to terminate ! 64: and returns the exit status of the command. ! 65: .PP ! 66: Because the ! 67: .I command ! 68: inherits open files, in particular standard input and output, a type ! 69: .L ! 70: "r" ! 71: call may be used to insert a filter in the input, and type ! 72: .L ! 73: "w" ! 74: in the output. ! 75: .SH "SEE ALSO" ! 76: .IR exec (2), ! 77: .IR pipe (2), ! 78: .IR fopen (3), ! 79: .IR stdio (3), ! 80: .IR system (3) ! 81: .SH DIAGNOSTICS ! 82: .I Popen ! 83: returns a null pointer ! 84: if files or processes cannot be created, or the Shell ! 85: cannot be accessed. ! 86: .PP ! 87: .I Pclose ! 88: returns \-1 ! 89: if there is ! 90: no process to wait for. ! 91: .SH BUGS ! 92: Buffered reading before opening an input filter ! 93: may leave the standard input of that filter mispositioned. ! 94: Similar problems with an output filter may be ! 95: forestalled by calling ! 96: .IR fflush ; ! 97: see ! 98: .IR fopen (3). ! 99: .br ! 100: The resetting of the userid ! 101: is probably gratuitous; ! 102: it is there as a defense against incautious use ! 103: of the routine by set-uid programs. ! 104: .br ! 105: I/O type ! 106: .L ! 107: "r+w" ! 108: exists but is not useful.
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.