Problem:
In Ruby, Open3.popen3 is a good way to execute a system command and get the output of the command. Following is the a piece of code that does this.
Open3.popen3(*cmd) do |stdin, stdout, stderr, wait_thread|
err = stderr.gets
out = stdout.gets
[stdin, stdout, stderr].each{|stream| stream.send('close')}
exit_status = wait_thread.value
end
It works well when your command throws some error to stderr. However, it got stuck forever if your command executes successfully without any error message, BECAUSE err=stderr.gets GOT STUCK.
Solution:
READ stdout FRIST
No comments:
Post a Comment