capture STDOUT data to a variable

S

Shaun Paul

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
 
J

Jean-Julien Fleck

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 =3D 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 =3D `D:\\softwares\\devcon.exe find *`

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

Cheers,

--=20
JJ Fleck
PCSI1 Lyc=E9e Kl=E9ber
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top