system ( ) call but suppressing =>true

  • Thread starter jackster the jackle
  • Start date
J

jackster the jackle

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
 
T

Tim Hunter

jackster said:
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.
 
M

Marc Heiler

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
 
L

Lee Jarvis

jackster said:
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
 
J

jackster the jackle

Thanks alot Marc....I used var = `#{x+y+z}` and it worked perfectly.

jackster



Marc said:
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
 
B

botp

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top