Logging stdout/stderr/stdin of an spawn process (Open4::spawn)

Discussion in 'Ruby' started by Ed Hames, Apr 16, 2008.

  1. Ed Hames

    Ed Hames Guest

    Hi dear rubyists,

    I need to log all the input (typed by the user) and the stdout/stderr
    of a process. The #script method below should behave pretty much like
    the Unix script application. This way, my application can issue
    several commands, show their output to the user an let them whatever
    is needed.

    def script cmd, log
    # prepare $stdin to save its content into log
    # prepare $stdout to save its content into log
    # prepare $stderr to save its content into log
    status = Open4::spawn cmd, 'stdin' => $stdin, 'stdout' =>
    $stdout, 'stderr' => $stderr
    end

    I've seen some implementations of a #tee function or Tee class, but
    they don't seem to work with spawn. What would you suggest?

    Thanks in advance,
    Ed
    Ed Hames, Apr 16, 2008
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jan Knop
    Replies:
    4
    Views:
    1,003
    Jan knob
    Nov 24, 2003
  2. Derek Basch
    Replies:
    2
    Views:
    1,280
    Donn Cave
    Jan 21, 2005
  3. Donn Cave
    Replies:
    0
    Views:
    390
    Donn Cave
    Apr 11, 2008
  4. Edgardo Hames
    Replies:
    1
    Views:
    326
    Ed Hames
    May 6, 2008
  5. Une Bévue

    Open4 : undefined method `spawn'

    Une Bévue, Sep 3, 2008, in forum: Ruby
    Replies:
    4
    Views:
    102
    Une Bévue
    Sep 9, 2008
Loading...

Share This Page