<?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>rel=me &#187; Airake</title>
	<atom:link href="http://rel.me/t/airake/feed/" rel="self" type="application/rss+xml" />
	<link>http://rel.me</link>
	<description>programming, objective-c, cocoa, iphone, c</description>
	<lastBuildDate>Wed, 01 Feb 2012 07:26:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>popen&#8217;ing part 2</title>
		<link>http://rel.me/2007/11/09/popen-ing-and-why-you-should-rtfm-before-blogging/</link>
		<comments>http://rel.me/2007/11/09/popen-ing-and-why-you-should-rtfm-before-blogging/#comments</comments>
		<pubDate>Fri, 09 Nov 2007 06:35:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Airake]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[process]]></category>

		<guid isPermaLink="false">/2007/11/11/popen-ing-and-why-you-should-rtfm-before-blogging</guid>
		<description><![CDATA[I guess I should rtfm before blogging about something. This is my new IO.popen block which allows you to run a process which wants input, like the adt (Adobe Debug Tool) package task (which asks for your certificate password): IO.popen&#40;@cmd&#41; do &#124;f&#124; while s = f.read&#40;1&#41; printf s STDOUT.flush end end @process = $? View [...]]]></description>
			<content:encoded><![CDATA[<p>I guess I should <a href="http://www.ruby-doc.org/core/classes/IO.html#M002267">rtfm</a> before blogging about something. This is my new IO.popen block which allows you to run a process which wants input, like the adt (Adobe Debug Tool) package task (which asks for your certificate password):</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span class="kw4">IO</span>.<span class="me1">popen</span><span class="br0">&#40;</span>@cmd<span class="br0">&#41;</span> <span class="kw1">do</span> <span class="sy0">|</span>f<span class="sy0">|</span>                        
  <span class="kw1">while</span> s = f.<span class="me1">read</span><span class="br0">&#40;</span><span class="nu0">1</span><span class="br0">&#41;</span>
    <span class="kw3">printf</span> s
    STDOUT.<span class="me1">flush</span>
  <span class="kw1">end</span>
<span class="kw1">end</span>
<span class="re1">@process</span> = $?</pre></div></div>

<p>View the <a href="http://airake.rubyforge.org/svn/trunk/lib/airake/runner.rb">airake/runner.rb</a>. The <a href="http://www.ruby-doc.org/core/classes/IO.html#M002295">IO.read</a> call if not given args will block until EOF. This means we can&#8217;t output anything until the process ends which makes it appear hung if its asking for input. The waitpid call in the previous version just picks up the Process::Status since the read was the blocking call, but you can get that from $? after the popen block returns. I needed to add the STDOUT flush since printf isn&#8217;t guaranteed to (and wasn&#8217;t) outputing on the adt password input since I think it waits for a newline. Also this totally works on windows, although the whole read char + printf + flush makes it feel like a typewriter. This might be solved by using the <a href="http://www.ruby-doc.org/core/classes/IO.html#M002292">IO.read_nonblock</a> method. I&#8217;ll need to look into that.</p>
<p>Also, I updated the blog css, which I was told was depressing. Now its a total ripoff of <a href="http://coudal.com">coudal.com</a> instead of <a href="http://danwebb.net">danwebb.net</a></p>
]]></content:encoded>
			<wfw:commentRss>http://rel.me/2007/11/09/popen-ing-and-why-you-should-rtfm-before-blogging/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

