# IO.popen how to separate $stdout and $stderr

**URL:** <https://www.ruby-forum.com/t/io-popen-how-to-separate-stdout-and-stderr/130232>\
**Category:** Ruby\
**Created:** [February 26, 2008, 4:26pm UTC](https://www.ruby-forum.com/t/io-popen-how-to-separate-stdout-and-stderr/130232 "2008-02-26T16:26:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Une\_BSSSSvS\_ue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/2acd7d/32.png) [@Une\_BSSSSvS\_ue](https://www.ruby-forum.com/u/Une_BSSSSvS_ue)\
**Post date:** [February 26, 2008, 4:26pm UTC](https://www.ruby-forum.com/t/io-popen-how-to-separate-stdout-and-stderr/130232/1 "2008-02-26T16:26:01Z")

</div>

when doing a :

r = IO.popen( cmd )

are the outputs of the cmd still separated in $stdout and stderr ?

how to retrieve them.

my basic usage is for an xslt transform (xslt 2.0) using saxon8.jar :

cmd = java -cp …/saxon-resources8-9/saxon8.jar net.sf.saxon.Transform  
“#{the\_xml\_file}” “#{the\_xsl\_file}”"

---

<div class="post-metadata">

**Author:** ![Une\_BSSSSvS\_ue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/2acd7d/32.png) [@Une\_BSSSSvS\_ue](https://www.ruby-forum.com/u/Une_BSSSSvS_ue)\
**Post date:** [February 27, 2008, 1:53am UTC](https://www.ruby-forum.com/t/io-popen-how-to-separate-stdout-and-stderr/130232/2 "2008-02-27T01:53:39Z")

</div>

Une Bévue wrote:

> cmd = java -cp …/saxon-resources8-9/saxon8.jar net.sf.saxon.Transform  
> "#{the\_xml\_file}" "#{the\_xsl\_file}""

From the documentation[1]:  
" Runs the specified command string as a subprocess; the subprocess’s  
standard input and output will be connected to the returned IO object."

This means you can reading from the returned IO object will get you the  
standard output and writing to it will send the data to the standard  
input of the application. This works just like any other IO of File  
object.

If you need to get standard error as well, you need to use  
Open3#popen3[2]

Hope that helps.  
-Justin

[1][class IO - RDoc Documentation](http://ruby-doc.org/core/classes/IO.html#M002267)  
[2][http://ruby-doc.org/core/classes/Open3.html](http://ruby-doc.org/core/classes/Open3.html)
