freeride-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [FR-devel] Executing and capturing process ouput


From: Laurent Julliard
Subject: Re: [FR-devel] Executing and capturing process ouput
Date: Fri, 10 May 2002 21:39:35 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0rc1) Gecko/20020417

Baptiste Lepilleur wrote:
    Hi all,
    I have a small question. As you may have noticed, the last version of
Practical Ruby allow the user to run a script.

    The current implementation use the backquote:

        output = `#{command} 2>&1`    # redirect stderr to stdout for
capture
where command is of the form:
        "ruby -I #{directory} #{scriptName}"

    while this work, it does not allow to print each line of the output to
the console window as soon as it is available. How does one do that ? My
guess is that it probably invole pipe, but I have no programming experience
with those (and even less in ruby).


Use the Open3 call. it is not very well documented so look directly into the source file: lib/ruby/1.6/open3.rb

It basically allows you to capture stdin, stdout and stderr of a child process in one call

Very useful.

Laurent





reply via email to

[Prev in Thread] Current Thread [Next in Thread]