📄 posix19.htm
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="GENERATOR" content="Quadralay WebWorks Publisher Professional Edition 6.0.5">
<meta name="TEMPLATEBASE" content="book_html">
<meta name="LASTUPDATED" content="12/04/03 16:07:18">
<title>17.8 Redirecting streams</title>
<STYLE TYPE="text/css">
<!--
span.Signal { text-transform: uppercase; font-family: Verdana }
-->
</STYLE>
</head>
<body link="#3366CC" vlink="#9999CC" text="#000000" alink="#0000CC" bgcolor="#FFFFFF"
background="images/backgrnd.gif">
<p><img src="images/stlogo.gif" width="106" height="83" align="left"
alt="logo here!"> </p>
<table width="331" border="0" align="right" cellpadding="0" cellspacing="0">
<tr>
<td><a href="a_refman.htm"><img src="images/navtoc.gif" width="84" height="23"
border="0" alt="TOC"> </a></td>
<td><a href="posix18.htm"><img src="images/navprev.gif" width="80" height="23"
border="0" alt="PREV"> </a></td>
<td><a href="posix20.htm"><img src="images/navnext.gif" width="83" height="23"
border="0" alt="NEXT"> </a></td>
<td><a href="a_refmaa.htm"><img src="images/navidx.gif" width="84" height="23"
border="0" alt="INDEX"> </a></td>
</tr>
</table>
<p><br clear="all">
</p>
<hr align="left">
<blockquote>
<h2>
<a name="1204671"> </a><font color="#003366" face="Verdana, Arial, Helvetica, sans-serif">17.8 Redirecting streams</font>
</h2><hr>
<p>
<a name="1204672"> </a><font size=2 face="Verdana, Arial, Helvetica, sans-serif">Is is often desirable to redirect I/O streams such as <font size=2 face=Courier><strong>stdin</strong></font>, <font size=2 face=Courier><strong>stdout</strong></font> and <font size=2 face=Courier><strong>stderr</strong></font> to a new device. By the time <font size=2 face=Courier><strong>main()</strong></font> is called, these have already been attached to the <font size=2 face=Courier><strong>dcu</strong></font> device. However, as no data has been buffered at this point, it is safe to change which device is associated with the file descriptor which a <font size=2 face=Courier><strong>FILE</strong></font> stream uses. A call to <font size=2 face=Courier><strong>dup()</strong></font> allocates the numerically lowest free file descriptor, so closing a file immediately prior to calling <font size=2 face=Courier><strong>dup()</strong></font> causes its file descriptor to be reused. The following example illustrates this property for redirecting <font size=2 face=Courier><strong>stdout</strong></font> to a new device.</font>
</p>
<p>
<a name="1204673"> </a><font size=2 face="Verdana, Arial, Helvetica, sans-serif">Example:</font>
</p>
<a name="1204674"> </a><font size=2 face=Courier><strong>int fd = open("asc0:",O_RDWR);<br>close(1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -