system ( ) call but suppressing =>true

Discussion in 'Ruby' started by jackster the jackle, Dec 19, 2007.

  1. I have a Perl script that takes a command line argument that I'm trying
    call from a Ruby (in Rails).

    The Perl script needs an IP address on the command line and runs as
    follows:

    /usr/bin/router.pl 172.21.1.1

    The following ruby code works perfectly for what I want but the only
    problem is that it returns "=>true" in addition to my data.

    I tried formulating a string and putting backquotes on it but couldn't
    get that to work. (example `x + y + z`)

    Is there any way to make system() suppress =>true?

    x = "/usr/bin/router.pl"
    y = " "
    z = "172.21.1.1"
    system(x + y + z)

    thanks again...

    jackster
    --
    Posted via http://www.ruby-forum.com/.
     
    jackster the jackle, Dec 19, 2007
    #1
    1. Advertising

  2. jackster the jackle

    Tim Hunter Guest

    jackster the jackle wrote:
    >
    > Is there any way to make system() suppress =>true?
    >
    > x = "/usr/bin/router.pl"
    > y = " "
    > z = "172.21.1.1"
    > system(x + y + z)
    >
    > thanks again...
    >
    > jackster


    You're trying this out in irb, aren't you? All you're seeing is irb
    printing the return value from system() so you can see what it returned.
    The system method doesn't really add "=>true" to the output from the
    command.

    --
    RMagick: http://rmagick.rubyforge.org/
     
    Tim Hunter, Dec 19, 2007
    #2
    1. Advertising

  3. jackster the jackle

    Marc Heiler Guest

    Instead of

    system(x + y + z)

    you could always use backticks and assign to a var (I think it is
    Kernel#`)

    var = `#{x+y+z}`

    or just use systemu and select what output is used.

    http://codeforpeople.com/lib/ruby/systemu/

    require 'systemu'
    status, stdout, stderr = systemu 'configure' # if you have a configure
    script
    p [ status, stdout, stderr ] # just select what to feedback the user
    --
    Posted via http://www.ruby-forum.com/.
     
    Marc Heiler, Dec 19, 2007
    #3
  4. jackster the jackle

    Lee Jarvis Guest

    jackster the jackle wrote:
    > The following ruby code works perfectly for what I want but the only
    > problem is that it returns "=>true" in addition to my data.
    >
    > I tried formulating a string and putting backquotes on it but couldn't
    > get that to work. (example `x + y + z`)
    >



    The Kernel#system method returns a boolean datatype, that is -- true if
    the command was ran sucessfully, false otherwise.

    Use backticks or %x{} is you want to store the output

    var = `#{ foo + bar + baz}` # as Marc said
    var = %x{ #{foo + bar + baz} } # Im pretty sure that works, sorry I
    can't test it right now.

    HTH

    Regards,
    Lee
    --
    Posted via http://www.ruby-forum.com/.
     
    Lee Jarvis, Dec 19, 2007
    #4
  5. Thanks alot Marc....I used var = `#{x+y+z}` and it worked perfectly.

    jackster



    Marc Heiler wrote:
    > Instead of
    >
    > system(x + y + z)
    >
    > you could always use backticks and assign to a var (I think it is
    > Kernel#`)
    >
    > var = `#{x+y+z}`
    >
    > or just use systemu and select what output is used.
    >
    > http://codeforpeople.com/lib/ruby/systemu/
    >
    > require 'systemu'
    > status, stdout, stderr = systemu 'configure' # if you have a configure
    > script
    > p [ status, stdout, stderr ] # just select what to feedback the user


    --
    Posted via http://www.ruby-forum.com/.
     
    jackster the jackle, Dec 19, 2007
    #5
  6. jackster the jackle

    botp Guest

    On Dec 19, 2007 10:49 PM, jackster the jackle <> wrote:
    > Thanks alot Marc....I used var = `#{x+y+z}` and it worked perfectly.


    fr your op, y is a space, so you may lose it, and do

    var = `#{x} #{z}`

    or

    x << " " << z
    var = `#{x}`

    or

    system x,z

    kind regards -botp
     
    botp, Dec 20, 2007
    #6
    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. Siemel Naran

    Does true ^ true return false?

    Siemel Naran, Jun 17, 2004, in forum: C++
    Replies:
    19
    Views:
    675
    Chris Theis
    Jun 18, 2004
  2. Chip
    Replies:
    6
    Views:
    2,651
    E. Robert Tisdale
    Jan 8, 2005
  3. Andy Leszczynski
    Replies:
    4
    Views:
    340
    Erik Max Francis
    Oct 13, 2005
  4. Replies:
    2
    Views:
    366
  5. bdb112
    Replies:
    45
    Views:
    1,373
    jazbees
    Apr 29, 2009
Loading...

Share This Page