How to capture the output of a call to Kernel.system

Discussion in 'Ruby' started by Wes Gamble, Jun 18, 2009.

  1. Wes Gamble

    Wes Gamble Guest

    I suspect that this is an extremely simple question to answer.

    How do you capture the output of a system call?

    For example, if I do this:

    >> x = system("date")

    Thu Jun 18 13:00:00 CDT 2009
    => true
    >> x

    => true

    I would like to capture the output of the date command. How do I do it?

    Thanks,
    Wes
    --
    Posted via http://www.ruby-forum.com/.
     
    Wes Gamble, Jun 18, 2009
    #1
    1. Advertising

  2. On Thu, Jun 18, 2009 at 2:01 PM, Wes Gamble<> wrote:
    > I suspect that this is an extremely simple question to answer.
    >
    > How do you capture the output of a system call?
    >
    > For example, if I do this:
    >
    >>> x =3D system("date")

    > Thu Jun 18 13:00:00 CDT 2009
    > =3D> true
    >>> x

    > =3D> true
    >
    > I would like to capture the output of the date command. =C2=A0How do I do=

    it?
    >


    x =3D `date`

    if you need to capture more than just stdout, i recommend the systemu gem.

    best,
    michael guterl
     
    Michael Guterl, Jun 18, 2009
    #2
    1. Advertising

  3. 2009/6/18 Michael Guterl <>:
    > On Thu, Jun 18, 2009 at 2:01 PM, Wes Gamble<> wrote:
    >> I suspect that this is an extremely simple question to answer.
    >>
    >> How do you capture the output of a system call?
    >>
    >> For example, if I do this:
    >>
    >>>> x =3D system("date")

    >> Thu Jun 18 13:00:00 CDT 2009
    >> =3D> true
    >>>> x

    >> =3D> true
    >>
    >> I would like to capture the output of the date command. =A0How do I do i=

    t?
    >
    > x =3D `date`
    >
    > if you need to capture more than just stdout, i recommend the systemu gem=
     
    Robert Klemme, Jun 19, 2009
    #3
    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. gooch

    linux kernel system call

    gooch, Oct 6, 2003, in forum: C Programming
    Replies:
    3
    Views:
    392
  2. yogesh
    Replies:
    3
    Views:
    590
    Kenny McCormack
    Feb 12, 2006
  3. Replies:
    3
    Views:
    178
  4. Chris Donhofer

    catching process output (Kernel#system)

    Chris Donhofer, Sep 23, 2006, in forum: Ruby
    Replies:
    11
    Views:
    232
    Chris Donhofer
    Sep 24, 2006
  5. Lars Gierth
    Replies:
    6
    Views:
    226
    David Masover
    Mar 20, 2010
Loading...

Share This Page