![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
The Oblivious One
Join Date: May 2005
Location: Ontario, Canada
Posts: 640
Rep Power: 4
![]() |
Start another program from Ruby and view ouput?
I have a stupid question.
I know in Ruby you can get the output of a command by encasing itin backquotes. For example: $ irb irb(main):001:0> output = `uname -r` => "2.6.20-ARCH\n" Now, my question. Say I have a program like apt-get (pacman in this case). What I want to do is start the program from inside a Ruby script and see the output as it's running. I think this is possible, because I've seen it done in other scripts (though not necessarily Ruby). Any ideas? ![]()
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS! |
|
|
|
|
|
#2 |
|
Programmer
|
You could try using IO :: popen:
$ irb
irb(main):001:0> io = IO::popen('echo 1 && sleep 10 && echo 2')
=> #<IO:0x4028c0fc>
irb(main):002:0> while io
irb(main):003:1> print io.readline
irb(main):004:1> end
1
2
EOFError: end of file reached
from (irb):3:in `readline'
from (irb):3
from :0(It's hard to tell by just reading this but there is a delay between when it prints 1 and 2 when I did it) |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|