[P]Open4 and stdin / stdout
From
=?UTF-8?Q?Une_B=c3=a9vue?=@21:1/5 to
All on Thu Jun 23 08:59:50 2016
I want to have a first script 'popen4-test.rb' calling another one 'inout-test.rb' with an input dialog.
'inout-test.rb' ask a question "What is the recipe type?"
and wait for the answer, here is 'inout-test.rb' : --------------------------------------------------------------------------------
#!/usr/bin/env ruby
# encoding: utf-8
require 'rubygems'
$stdout.puts "What is the recipe type?"
sleep 1.0
r_type = $stdin.gets.chomp
$stdout.puts "Recipe type: '#{r_type}'."
sleep 5.0
$stdout.puts "Bye!" --------------------------------------------------------------------------------
Notice that 'inout-test.rb' works as expected when called directly by "./inout-test.rb".
here is 'popen4-test.rb' : --------------------------------------------------------------------------------
#!/usr/bin/env ruby
# encoding: utf-8
require 'rubygems'
require "open4" # or popen4
cmd = '/home/yt/bin/tests/inout-test.rb'
status =
Open4::popen4(cmd) do |pid, stdin, stdout, stderr|
out = stdout.read.strip
if out.include? 'type'
puts out
r_type = gets.chomp
stdin.puts r_type
end
stdin.close if out.include? 'Bye!'
puts "pid : #{ pid }"
puts "stderr : #{ stderr.read.strip }"
end
puts "status : #{ status.inspect }"
puts "exitstatus : #{ status.exitstatus }" --------------------------------------------------------------------------------
Then, 'popen4-test.rb' is supposed to forward the question to the terminal.
But this does not work, 'popen4-test.rb' hangs if 'inout-test.rb' has a "$stdin.gets".
However if I comment out the lines, in 'inout-test.rb', related to this "$stdin.gets", 'popen4-test.rb' does not hang any more.
Something wrong in my test, but what?
The purpose of this test is to simulate a socket server asking for a
script to be launched (here 'inout-test.rb') and forwardind the
questions to the client...
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)