# How to capture the output of a call to Kernel.system

**URL:** <https://www.ruby-forum.com/t/how-to-capture-the-output-of-a-call-to-kernel-system/170549>\
**Category:** Ruby\
**Created:** [June 18, 2009, 8:01pm UTC](https://www.ruby-forum.com/t/how-to-capture-the-output-of-a-call-to-kernel-system/170549 "2009-06-18T20:01:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [June 18, 2009, 8:01pm UTC](https://www.ruby-forum.com/t/how-to-capture-the-output-of-a-call-to-kernel-system/170549/1 "2009-06-18T20:01:46Z")

</div>

I suspect that this is an extremely simple question to answer.

How do you capture the output of a system call?

For example, if I do this:

> > x = system(“date”)  
> > Thu Jun 18 13:00:00 CDT 2009  
> > =\> true
> 
> > x  
> > =\> true

I would like to capture the output of the date command. How do I do it?

Thanks,  
Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [June 18, 2009, 8:20pm UTC](https://www.ruby-forum.com/t/how-to-capture-the-output-of-a-call-to-kernel-system/170549/2 "2009-06-18T20:20:44Z")

</div>

On Thu, Jun 18, 2009 at 2:01 PM, Wes G.[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> =\> true
> 
> I would like to capture the output of the date command. Â How do I do it?

x = `date`

if you need to capture more than just stdout, i recommend the systemu  
gem.

best,  
michael guterl

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [June 19, 2009, 9:56am UTC](https://www.ruby-forum.com/t/how-to-capture-the-output-of-a-call-to-kernel-system/170549/3 "2009-06-19T09:56:56Z")

</div>

2009/6/18 Michael G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> > > > x  
> > > > =\> true
> > 
> > I would like to capture the output of the date command. How do I do it?
> 
> x = `date`
> 
> if you need to capture more than just stdout, i recommend the systemu gem.

There’s also IO.popen and Open3.popen which are part of the standard  
library IIRC.

Kind regards

robert
