74 lines
2.3 KiB
HTML
74 lines
2.3 KiB
HTML
<HTML>
|
|
<HEAD>
|
|
<TITLE>popen(3)</TITLE>
|
|
</HEAD>
|
|
<BODY>
|
|
<H1>popen(3)</H1>
|
|
<HR>
|
|
<PRE>
|
|
|
|
</PRE>
|
|
<H2>NAME</H2><PRE>
|
|
popen, pclose - initiate I/O to/from a process
|
|
|
|
|
|
</PRE>
|
|
<H2>SYNOPSIS</H2><PRE>
|
|
<STRONG>#include</STRONG> <STRONG><stdio.h></STRONG>
|
|
|
|
<STRONG>FILE</STRONG> <STRONG>*popen(const</STRONG> <STRONG>char</STRONG> <STRONG>*command,</STRONG> <STRONG>const</STRONG> <STRONG>char</STRONG> <STRONG>*type)</STRONG>
|
|
<STRONG>int</STRONG> <STRONG>pclose(FILE</STRONG> <STRONG>*stream)</STRONG>
|
|
|
|
|
|
</PRE>
|
|
<H2>DESCRIPTION</H2><PRE>
|
|
The arguments to <STRONG>popen</STRONG> 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 <STRONG>popen</STRONG> should be closed by <STRONG>pclose</STRONG>, 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.
|
|
|
|
|
|
</PRE>
|
|
<H2>SEE ALSO</H2><PRE>
|
|
<STRONG><A HREF="../man2/pipe.2.html">pipe(2)</A></STRONG>, <STRONG><A HREF="../man3/fopen.3.html">fopen(3)</A></STRONG>, <STRONG><A HREF="../man3/fclose.3.html">fclose(3)</A></STRONG>, <STRONG><A HREF="../man3/system.3.html">system(3)</A></STRONG>, <STRONG><A HREF="../man2/wait.2.html">wait(2)</A></STRONG>, <STRONG><A HREF="../man1/sh.1.html">sh(1)</A></STRONG>.
|
|
|
|
|
|
</PRE>
|
|
<H2>DIAGNOSTICS</H2><PRE>
|
|
<STRONG>Popen</STRONG> returns a null pointer if files or processes cannot be created, or
|
|
the shell cannot be accessed.
|
|
|
|
|
|
</PRE>
|
|
<H2>BUGS</H2><PRE>
|
|
Buffered reading before opening an input filter may leave the standard
|
|
input of that filter mispositioned. Similar problems with an output
|
|
filter may be forestalled by careful buffer flushing, for instance, with
|
|
<STRONG>fflush</STRONG>, see <STRONG><A HREF="../man3/fclose.3.html">fclose(3)</A></STRONG>.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</PRE>
|
|
</BODY>
|
|
</HTML>
|