# Capture STDOUT data to a variable

**URL:** <https://www.ruby-forum.com/t/capture-stdout-data-to-a-variable/191813>\
**Category:** Ruby\
**Created:** [July 19, 2010, 9:50am UTC](https://www.ruby-forum.com/t/capture-stdout-data-to-a-variable/191813 "2010-07-19T09:50:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![shaunp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/35a633/32.png) [@shaunp](https://www.ruby-forum.com/u/shaunp)\
**Post date:** [July 19, 2010, 9:50am UTC](https://www.ruby-forum.com/t/capture-stdout-data-to-a-variable/191813/1 "2010-07-19T09:50:42Z")

</div>

Hello

I am fetching some data from windows using a simple ruby script using  
system command, which is outputting the data onto STDOUT. But I need the  
same to get dumped to a local variable.  
how can I acheive this? the code snippet I am using is as below

result = system(“D:\softwares\devcon.exe find \*”)

This lists out all the devices in device manager onto STDOUT and returns  
a ‘true’ to the variable result. How do I capture the actual data to the  
variabel result instead?

Thanks  
Shaun

---

<div class="post-metadata">

**Author:** ![shaunp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/35a633/32.png) [@shaunp](https://www.ruby-forum.com/u/shaunp)\
**Post date:** [July 19, 2010, 10:17am UTC](https://www.ruby-forum.com/t/capture-stdout-data-to-a-variable/191813/2 "2010-07-19T10:17:59Z")

</div>

Hello Shaun,

> I am fetching some data from windows using a simple ruby script using  
> system command, which is outputting the data onto STDOUT. But I need the  
> same to get dumped to a local variable.  
> how can I acheive this? the code snippet I am using is as below
> 
> result = system(“D:\softwares\devcon.exe find \*”)

If it works on windows as it does on Mac and Linux, you just have to  
use backsticks:

result = `D:\\softwares\\devcon.exe find *`

You could also look at IO.popen to get a bit more flexibility.

Cheers,
