4

I'm currently making a ruby script that takes in a python script and prints the output. The ruby code is more or less the same from here:

begin
  PTY.spawn("python temp.py") do |stdout, stdin, pid|
    begin
      stdout.each { |line| print line }
    rescue Errno::EIO
      puts ""
    end
  end
rescue PTY::ChildExited
  puts "The child process exited!"
end

The python code, for the sake of testing, is straightforward:

for each in range(10):
    print each
raw_input(">")

When the ruby file is run, it prints 0 to 10, then hangs without printing the ">" symbol. This is to be expected as Python is waiting for a user input at that point.

Is it possible, however, for the PTY to print 0 to 10, the ">" symbol, and just end the process then and there? To do this I presume Ruby would have to check if PTY is waiting for an input, but how would that be done?

therladbsgh
  • 71
  • 1
  • 4

0 Answers0