IO.popen how to separate $stdout and $stderr

Discussion in 'Ruby' started by Une Bévue, Feb 26, 2008.

  1. Une Bévue

    Une Bévue Guest

    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}\""
    Une Bévue, Feb 26, 2008
    1. Advertisements

  2. 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 Collins, Feb 27, 2008
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.