Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v8plus / html / python / lib / os-newstreams.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python Documentation Index' />
<link rel="first" href="lib.html" title='Python Library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="next" href="os-fd-ops.html" />
<link rel="prev" href="os-procinfo.html" />
<link rel="parent" href="module-os.html" />
<link rel="next" href="os-fd-ops.html" />
<meta name='aesop' content='information' />
<title>6.1.2 File Object Creation </title>
</head>
<body>
<DIV CLASS="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="6.1.1 Process Parameters"
href="os-procinfo.html"><img src='../icons/previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="6.1 os "
href="module-os.html"><img src='../icons/up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="6.1.3 File Descriptor Operations"
href="os-fd-ops.html"><img src='../icons/next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
href="contents.html"><img src='../icons/contents.png'
border='0' height='32' alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
border='0' height='32' alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
href="genindex.html"><img src='../icons/index.png'
border='0' height='32' alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="os-procinfo.html">6.1.1 Process Parameters</A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-os.html">6.1 os </A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="os-fd-ops.html">6.1.3 File Descriptor Operations</A>
</div>
<hr /></div>
</DIV>
<!--End of Navigation Panel-->
<H2><A NAME="SECTION008120000000000000000"></A><A NAME="os-newstreams"></A>
<BR>
6.1.2 File Object Creation
</H2>
<P>
These functions create new file objects.
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1551' xml:id='l2h-1551' class="function">fdopen</tt></b>(</nobr></td>
<td><var>fd</var><big>[</big><var>, mode</var><big>[</big><var>, bufsize</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Return an open file object connected to the file descriptor <var>fd</var>.
<a id='l2h-1557' xml:id='l2h-1557'></a>
The <var>mode</var> and <var>bufsize</var> arguments have the same meaning as
the corresponding arguments to the built-in <tt class="function">open()</tt>
function.
Availability: Macintosh, <span class="Unix">Unix</span>, Windows.
<P>
<span class="versionnote">Changed in version 2.3:
When specified, the <var>mode</var> argument must now start
with one of the letters "<tt class="character">r</tt>", "<tt class="character">w</tt>", or "<tt class="character">a</tt>",
otherwise a <tt class="exception">ValueError</tt> is raised.</span>
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1552' xml:id='l2h-1552' class="function">popen</tt></b>(</nobr></td>
<td><var>command</var><big>[</big><var>, mode</var><big>[</big><var>, bufsize</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Open a pipe to or from <var>command</var>. The return value is an open
file object connected to the pipe, which can be read or written
depending on whether <var>mode</var> is <code>'r'</code> (default) or <code>'w'</code>.
The <var>bufsize</var> argument has the same meaning as the corresponding
argument to the built-in <tt class="function">open()</tt> function. The exit status of
the command (encoded in the format specified for <tt class="function">wait()</tt>) is
available as the return value of the <tt class="method">close()</tt> method of the file
object, except that when the exit status is zero (termination without
errors), <code>None</code> is returned.
Availability: Macintosh, <span class="Unix">Unix</span>, Windows.
<P>
<span class="versionnote">Changed in version 2.0:
This function worked unreliably under Windows in
earlier versions of Python. This was due to the use of the
<tt class="cfunction">_popen()</tt> function from the libraries provided with
Windows. Newer versions of Python do not use the broken
implementation from the Windows libraries.</span>
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1553' xml:id='l2h-1553' class="function">tmpfile</tt></b>(</nobr></td>
<td><var></var>)</td></tr></table></dt>
<dd>
Return a new file object opened in update mode ("<tt class="samp">w+b</tt>"). The file
has no directory entries associated with it and will be automatically
deleted once there are no file descriptors for the file.
Availability: Macintosh, <span class="Unix">Unix</span>, Windows.
</dl>
<P>
For each of the following <tt class="function">popen()</tt> variants, if <var>bufsize</var> is
specified, it specifies the buffer size for the I/O pipes.
<var>mode</var>, if provided, should be the string <code>'b'</code> or
<code>'t'</code>; on Windows this is needed to determine whether the file
objects should be opened in binary or text mode. The default value
for <var>mode</var> is <code>'t'</code>.
<P>
Also, for each of these variants, on <span class="Unix">Unix</span>, <var>cmd</var> may be a sequence, in
which case arguments will be passed directly to the program without shell
intervention (as with <tt class="function">os.spawnv()</tt>). If <var>cmd</var> is a string it will
be passed to the shell (as with <tt class="function">os.system()</tt>).
<P>
These methods do not make it possible to retrieve the exit status from
the child processes. The only way to control the input and output
streams and also retrieve the return codes is to use the
<tt class="class">Popen3</tt> and <tt class="class">Popen4</tt> classes from the <tt class="module"><a href="module-popen2.html">popen2</a></tt>
module; these are only available on <span class="Unix">Unix</span>.
<P>
For a discussion of possible deadlock conditions related to the use
of these functions, see ``<a class="ulink" href="popen2-flow-control.html"
>Flow Control
Issues</a>''
(section&nbsp;<A href="popen2-flow-control.html#popen2-flow-control">6.9.2</A>).
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1554' xml:id='l2h-1554' class="function">popen2</tt></b>(</nobr></td>
<td><var>cmd</var><big>[</big><var>, mode</var><big>[</big><var>, bufsize</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Executes <var>cmd</var> as a sub-process. Returns the file objects
<code>(<var>child_stdin</var>, <var>child_stdout</var>)</code>.
Availability: Macintosh, <span class="Unix">Unix</span>, Windows.
<span class="versionnote">New in version 2.0.</span>
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1555' xml:id='l2h-1555' class="function">popen3</tt></b>(</nobr></td>
<td><var>cmd</var><big>[</big><var>, mode</var><big>[</big><var>, bufsize</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Executes <var>cmd</var> as a sub-process. Returns the file objects
<code>(<var>child_stdin</var>, <var>child_stdout</var>, <var>child_stderr</var>)</code>.
Availability: Macintosh, <span class="Unix">Unix</span>, Windows.
<span class="versionnote">New in version 2.0.</span>
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1556' xml:id='l2h-1556' class="function">popen4</tt></b>(</nobr></td>
<td><var>cmd</var><big>[</big><var>, mode</var><big>[</big><var>, bufsize</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Executes <var>cmd</var> as a sub-process. Returns the file objects
<code>(<var>child_stdin</var>, <var>child_stdout_and_stderr</var>)</code>.
Availability: Macintosh, <span class="Unix">Unix</span>, Windows.
<span class="versionnote">New in version 2.0.</span>
</dl>
<P>
(Note that <code><var>child_stdin</var>, <var>child_stdout</var>, and
<var>child_stderr</var></code> are named from the point of view of the child
process, i.e. <var>child_stdin</var> is the child's standard input.)
<P>
This functionality is also available in the <tt class="module"><a href="module-popen2.html">popen2</a></tt> module
using functions of the same names, but the return values of those
functions have a different order.
<P>
<DIV CLASS="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="6.1.1 Process Parameters"
href="os-procinfo.html"><img src='../icons/previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="6.1 os "
href="module-os.html"><img src='../icons/up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="6.1.3 File Descriptor Operations"
href="os-fd-ops.html"><img src='../icons/next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
href="contents.html"><img src='../icons/contents.png'
border='0' height='32' alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
border='0' height='32' alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
href="genindex.html"><img src='../icons/index.png'
border='0' height='32' alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="os-procinfo.html">6.1.1 Process Parameters</A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-os.html">6.1 os </A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="os-fd-ops.html">6.1.3 File Descriptor Operations</A>
</div>
</div>
<hr />
<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>