Forum: Ruby How to capture the output of system("")?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2932e97aee5aad3e4a0aa21ed26b30b3?d=identicon&s=25 Yingqi Tang (anakintang)
on 2007-06-04 19:36
All,

When I can system("...") in ruby, I got either true or false returned,
but how do I capture the information that being printed out in console
when the cmd is being executed?

Thanks
7a561ec0875fcbbe3066ea8fe288ec77?d=identicon&s=25 Sebastian Hungerecker (Guest)
on 2007-06-04 19:48
(Received via mailing list)
Yingqi Tang wrote:
> When I can system("...") in ruby, I got either true or false returned,
> but how do I capture the information that being printed out in console
> when the cmd is being executed?

By using backticks or %x{} instead of system.
9d4960f8319664f0f7896230eebace73?d=identicon&s=25 Glen Holcomb (Guest)
on 2007-06-04 19:49
(Received via mailing list)
use `` instead of system("")

On 6/4/07, Yingqi Tang <yingqitang@gmail.com> wrote:
> Posted via http://www.ruby-forum.com/.
>
>


--
"Hey brother christian with your high and mighty errand, Your actions
speak
so loud, I can't hear a word you're saying."

-Greg Graffin (Bad Religion)
9d4960f8319664f0f7896230eebace73?d=identicon&s=25 Glen Holcomb (Guest)
on 2007-06-04 19:51
(Received via mailing list)
for example `ls /etc`

On 6/4/07, Glen Holcomb <damnbigman@gmail.com> wrote:
> >
> speak so loud, I can't hear a word you're saying."
>
> -Greg Graffin (Bad Religion)




--
"Hey brother christian with your high and mighty errand, Your actions
speak
so loud, I can't hear a word you're saying."

-Greg Graffin (Bad Religion)
E92d09efe27bf50a87967c533fae247a?d=identicon&s=25 unknown (Guest)
on 2007-06-04 21:31
(Received via mailing list)
On Jun 4, 10:47 am, Sebastian Hungerecker <sep...@googlemail.com>
wrote:
> Yingqi Tang wrote:
> > When I can system("...") in ruby, I got either true or false returned,
> > but how do I capture the information that being printed out in console
> > when the cmd is being executed?
>
> By using backticks or %x{} instead of system.
>
> --
> Ist so, weil ist so
> Bleibt so, weil war so

Another option besides backticks or %x{} is to use IO#popen.  This is
useful if you want to read output in the same manner as you would with
a file.
This topic is locked and can not be replied to.