# How to capture the output of system("")?

**URL:** <https://www.ruby-forum.com/t/how-to-capture-the-output-of-system/105928>\
**Category:** Ruby\
**Created:** [June 4, 2007, 7:36pm UTC](https://www.ruby-forum.com/t/how-to-capture-the-output-of-system/105928 "2007-06-04T19:36:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anakintang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/5fc32e/32.png) [@anakintang](https://www.ruby-forum.com/u/anakintang)\
**Post date:** [June 4, 2007, 7:36pm UTC](https://www.ruby-forum.com/t/how-to-capture-the-output-of-system/105928/1 "2007-06-04T19:36:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anakintang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/5fc32e/32.png) [@anakintang](https://www.ruby-forum.com/u/anakintang)\
**Post date:** [June 4, 2007, 7:48pm UTC](https://www.ruby-forum.com/t/how-to-capture-the-output-of-system/105928/2 "2007-06-04T19:48:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anakintang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/5fc32e/32.png) [@anakintang](https://www.ruby-forum.com/u/anakintang)\
**Post date:** [June 4, 2007, 7:49pm UTC](https://www.ruby-forum.com/t/how-to-capture-the-output-of-system/105928/3 "2007-06-04T19:49:21Z")

</div>

use `` instead of system(“”)

On 6/4/07, Yingqi T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Posted via [http://www.ruby-forum.com/](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)

---

<div class="post-metadata">

**Author:** ![anakintang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/5fc32e/32.png) [@anakintang](https://www.ruby-forum.com/u/anakintang)\
**Post date:** [June 4, 2007, 9:31pm UTC](https://www.ruby-forum.com/t/how-to-capture-the-output-of-system/105928/4 "2007-06-04T21:31:11Z")

</div>

On Jun 4, 10:47 am, Sebastian H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

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

---

<div class="post-metadata">

**Author:** ![anakintang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/5fc32e/32.png) [@anakintang](https://www.ruby-forum.com/u/anakintang)\
**Post date:** [June 4, 2007, 7:51pm UTC](https://www.ruby-forum.com/t/how-to-capture-the-output-of-system/105928/5 "2007-06-04T19:51:21Z")

</div>

for example `ls /etc`

On 6/4/07, Glen H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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)
