[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

system ( ) call but suppressing =>true

jackster the jackle

12/19/2007 1:06:00 AM

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-....

5 Answers

Tim Hunter

12/19/2007 1:21:00 AM

0

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.ruby...

Marc Heiler

12/19/2007 9:59:00 AM

0

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/rub...

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-....

Lee Jarvis

12/19/2007 1:19:00 PM

0

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-....

jackster the jackle

12/19/2007 2:49:00 PM

0

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/rub...
>
> 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-....

botp

12/20/2007 3:42:00 AM

0

On Dec 19, 2007 10:49 PM, jackster the jackle <contact@thirdorder.net> 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