Created
February 25, 2010 02:59
-
-
Save knzai/314180 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#http://github.com/ahoward/open4 is an alternative that handles pid and exit status | |
#http://github.com/ahoward/session a more fleshed our shell utility | |
require 'open3' | |
Open3.popen3("dc") do |stdin, stdout, stderr| | |
t = Thread.new(stderr) do |terr| | |
while (line = terr.gets) | |
puts "stderr: #{line}" | |
end | |
end | |
puts "pushing 5 to stack" | |
stdin.puts(5) | |
puts "pushing 10 to stack" | |
stdin.puts(10) | |
puts "pushing + to stack" | |
stdin.puts("+") | |
puts "sending print command" | |
stdin.puts("p") | |
result = stdout.gets | |
puts "stdout: #{ result }" | |
puts "\ntrying an unsupported command" | |
stdin.puts("b") | |
extra_info_not_in_stderror = stdout.gets | |
puts "stdout: #{extra_info_not_in_stderror}" | |
puts "\nclosing stdin to avoid deadlock with stderr" | |
stdin.close | |
# puts "let's give stderr a chance to run" | |
# t.run or sleep 1 | |
puts "joining" | |
t.join | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment