<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Segment7: $stdout vs STDOUT</title>
    <link>http://blog.segment7.net/articles/2006/08/17/stdout-vs-stdout</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>The Blog</description>
    <item>
      <title>$stdout vs STDOUT</title>
      <description>&lt;p&gt;You may have noticed me using both &lt;code&gt;$stdout&lt;/code&gt; and &lt;code&gt;STDOUT&lt;/code&gt; in my &lt;a href="http://blog.segment7.net/articles/2006/08/16/setting-stdout-per-thread"&gt;last post&lt;/a&gt; and been puzzled by how I could use both.&lt;/p&gt;


	&lt;p&gt;When Ruby starts up the process&amp;#8217; standard output file descriptor is stored in both the constant &lt;span class="caps"&gt;STDOUT&lt;/span&gt; and the global variable $stdout.  &lt;span class="caps"&gt;STDOUT&lt;/span&gt; holds the process&amp;#8217; original stdout while $stdout is reassignable.  Kernel#puts and friends use $stdout to write their output, not &lt;span class="caps"&gt;STDOUT&lt;/span&gt;.&lt;/p&gt;


	&lt;p&gt;To be most-friendly, when you want to redirect stdout you should assign to $stdout instead of fiddling with &lt;span class="caps"&gt;STDOUT&lt;/span&gt;.  When outputting to an explicit file descriptor, use $stdout or $stderr instead of &lt;span class="caps"&gt;STDOUT&lt;/span&gt; or &lt;span class="caps"&gt;STDERR&lt;/span&gt;.&lt;/p&gt;


	&lt;p&gt;&lt;span class="caps"&gt;STDOUT&lt;/span&gt; can only be changed by calling IO#reopen, but you can assign any object that responds to #write to $stdout, which is what made my ThreadOut hack work.&lt;/p&gt;
</description>
      <pubDate>Thu, 17 Aug 2006 09:47:00 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:0dea8ea0-a6ee-4ecf-bb93-8ddd47633b85</guid>
      <author>drbrain@segment7.net (Eric Hodel)</author>
      <link>http://blog.segment7.net/articles/2006/08/17/stdout-vs-stdout</link>
      <category>Ruby</category>
    </item>
    <item>
      <title>"$stdout vs STDOUT" by Daniel Berger</title>
      <description>&lt;p&gt;Nice, thanks.&lt;/p&gt;</description>
      <pubDate>Thu, 17 Aug 2006 12:14:01 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:8b4dbce5-0f58-4c25-a61e-0bdf1cbea8d7</guid>
      <link>http://blog.segment7.net/articles/2006/08/17/stdout-vs-stdout#comment-292</link>
    </item>
  </channel>
</rss>
