Problem: call an external process, wait till it finishes, get its stdout
and stderr as Strings, as well as the exit status.
My current approximation of the solution:
stdout = IO.popen("myprocess.sh").readlines
exitStatus = $?
It doesn't work. exitStatus comes out as nil. I probably understand why.
Naturally, one can always bite the bullet and write the whole story
(open a Process, attach two reader threads, direct all output streams
into Ruby strings, wait till the Process quits, etc). This would be a
lot of code for a common scripting task, and from past experiences doing
same thing with C and Java, there are a few interesting surprises.
Can some enlightened soul please show me The Ruby Way to do it all in
one line? Reference to an appropriate page in the Pickaxe that I should
have RTFM'd not to ask this silly question would be even better :)
Domo arigato in advance.
Best regards,
Alexey Verkhovsky