IO.popen how to separate $stdout and $stderr

U

Une Bévue

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}\""
 
J

Justin Collins

Une said:
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}\""

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]http://ruby-doc.org/core/classes/IO.html#M002267
[2]http://ruby-doc.org/core/classes/Open3.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,832
Latest member
GlennSmall

Latest Threads

Top