Possible Duplicate:
Running a command from Ruby displaying and capturing the output
I have to execute a program on my local server and get, in a variable, the console's output
Possible Duplicate:
Running a command from Ruby displaying and capturing the output
I have to execute a program on my local server and get, in a variable, the console's output
$ irb
1.9.3p125 :001 > cal = %x[/usr/bin/cal]
1.9.3p125 :002 > puts cal
June 2012
Su Mo Tu We Th Fr Sa
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
You can redirect output with IO reopen.
$stdout.reopen("stdout.txt", "w")
$stderr.reopen("stderr.txt", "w")
puts 'stdout redirect'
warn 'stderr redirect'