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
jackster the jackle wrote:
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.
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
Thanks alot Marc…I used var = #{x+y+z}
and it worked perfectly.
jackster
Marc H. 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
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
On Dec 19, 2007 10:49 PM, jackster the jackle [email protected]
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