<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Rainux's Journal &#187; PHP Archives  &laquo; Rainux&#039;s Journal</title>
	<atom:link href="http://rainux.org/category/programming/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://rainux.org</link>
	<description>Rubyist of Vimmer</description>
	<lastBuildDate>Sat, 23 Jul 2011 12:09:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>使用 Linux shell I/O 重定向简化小程序的日志记录</title>
		<link>http://rainux.org/%e4%bd%bf%e7%94%a8-linux-shell-io-%e9%87%8d%e5%ae%9a%e5%90%91%e7%ae%80%e5%8c%96%e5%b0%8f%e7%a8%8b%e5%ba%8f%e7%9a%84%e6%97%a5%e5%bf%97%e8%ae%b0%e5%bd%95</link>
		<comments>http://rainux.org/%e4%bd%bf%e7%94%a8-linux-shell-io-%e9%87%8d%e5%ae%9a%e5%90%91%e7%ae%80%e5%8c%96%e5%b0%8f%e7%a8%8b%e5%ba%8f%e7%9a%84%e6%97%a5%e5%bf%97%e8%ae%b0%e5%bd%95#comments</comments>
		<pubDate>Sun, 11 Mar 2007 19:04:46 +0000</pubDate>
		<dc:creator>Rainux</dc:creator>
				<category><![CDATA[GNU/Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming 编程]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[Programming_编程]]></category>

		<guid isPermaLink="false">http://www.rainux.org/2007/03/12/146</guid>
		<description><![CDATA[一些自动执行特定任务的小脚本程序，如果希望能使程序的 stdout/stderr 输出到屏幕的同时也把他们记录到一个日志文件，可以使用 tee 命令结合 shell I/O 重定向来轻松完成: ./a_tiny_script 2&#62;&#38;1 &#124; tee the_log_contain_both_stdout_and_stderr.log 这个命令的精华在于 2>&#38;1，意为让 stderr 使用 stdout 的文件描述符，效果也就是将 stdout 和 stderr 内容合并，并且输出到 stdout 被定向的位置。在这里也就是管道中的 tee 命令的 stdin 上，然后 tee 将得到的输入同时显示在屏幕上和记录到日志文件里。爽吧？ 以前为了在 PHP 脚本里实现这样的功能竟然使用了 ob 系列函数 + 自定义的 output callback 函数，并且这样也只能做到同时显示和记录 stdout，真是晕到死。 标签：bash, GNU/Linux, PHP, Programming_编程]]></description>
			<content:encoded><![CDATA[<p>一些自动执行特定任务的小脚本程序，如果希望能使程序的 stdout/stderr 输出到屏幕的同时也把他们记录到一个日志文件，可以使用 tee 命令结合 shell I/O 重定向来轻松完成:</p>

<pre name="code" class="bash">./a_tiny_script 2&gt;&amp;1 | tee the_log_contain_both_stdout_and_stderr.log
</pre>

<p>这个命令的精华在于 2>&amp;1，意为让 stderr 使用 stdout 的文件描述符，效果也就是将 stdout 和 stderr 内容合并，并且输出到 stdout 被定向的位置。在这里也就是管道中的 tee 命令的 stdin 上，然后 tee 将得到的输入同时显示在屏幕上和记录到日志文件里。爽吧？</p>

<p>以前为了在 PHP 脚本里实现这样的功能竟然使用了 ob 系列函数 + 自定义的 output callback 函数，并且这样也只能做到同时显示和记录 stdout，真是晕到死。</p>

	标签：<a href="http://rainux.org/tag/bash/" title="bash" rel="tag">bash</a>, <a href="http://rainux.org/tag/gnu-linux/" title="GNU/Linux" rel="tag">GNU/Linux</a>, <a href="http://rainux.org/tag/php/" title="PHP" rel="tag">PHP</a>, <a href="http://rainux.org/tag/programming_%e7%bc%96%e7%a8%8b/" title="Programming_编程" rel="tag">Programming_编程</a><br />
]]></content:encoded>
			<wfw:commentRss>http://rainux.org/%e4%bd%bf%e7%94%a8-linux-shell-io-%e9%87%8d%e5%ae%9a%e5%90%91%e7%ae%80%e5%8c%96%e5%b0%8f%e7%a8%8b%e5%ba%8f%e7%9a%84%e6%97%a5%e5%bf%97%e8%ae%b0%e5%bd%95/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

