# System ( ) call but suppressing =\>true

**URL:** <https://www.ruby-forum.com/t/system-call-but-suppressing-true/123601>\
**Category:** Ruby\
**Created:** [December 19, 2007, 2:05am UTC](https://www.ruby-forum.com/t/system-call-but-suppressing-true/123601 "2007-12-19T02:05:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jackster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jackster](https://www.ruby-forum.com/u/jackster)\
**Post date:** [December 19, 2007, 2:05am UTC](https://www.ruby-forum.com/t/system-call-but-suppressing-true/123601/1 "2007-12-19T02:05:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jackster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jackster](https://www.ruby-forum.com/u/jackster)\
**Post date:** [December 19, 2007, 2:22am UTC](https://www.ruby-forum.com/t/system-call-but-suppressing-true/123601/2 "2007-12-19T02:22:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jackster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jackster](https://www.ruby-forum.com/u/jackster)\
**Post date:** [December 19, 2007, 10:58am UTC](https://www.ruby-forum.com/t/system-call-but-suppressing-true/123601/3 "2007-12-19T10:58:54Z")

</div>

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/](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

---

<div class="post-metadata">

**Author:** ![jackster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jackster](https://www.ruby-forum.com/u/jackster)\
**Post date:** [December 19, 2007, 3:49pm UTC](https://www.ruby-forum.com/t/system-call-but-suppressing-true/123601/4 "2007-12-19T15:49:10Z")

</div>

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/](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

---

<div class="post-metadata">

**Author:** ![jackster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jackster](https://www.ruby-forum.com/u/jackster)\
**Post date:** [December 19, 2007, 2:19pm UTC](https://www.ruby-forum.com/t/system-call-but-suppressing-true/123601/5 "2007-12-19T14:19:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jackster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jackster](https://www.ruby-forum.com/u/jackster)\
**Post date:** [December 20, 2007, 4:43am UTC](https://www.ruby-forum.com/t/system-call-but-suppressing-true/123601/6 "2007-12-20T04:43:26Z")

</div>

On Dec 19, 2007 10:49 PM, jackster the jackle [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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
