Like tcl expect?

I want to run a ruby script within another ruby script in an
‘interactive’ mode like tcl/expect does.

When the script outputs
Please enter your name:
I want to ‘write to stdout’ my name. + “\n” etc.

then go on to the next question that the script will output.

Right now I have one ruby script that just produces a report…

myrep=./myreport.rb

but it’s just a dumb output and doesn’t interact with the user.

So…
How can I fork the interactive script and read stdin and write std out
such that I can controls the interactive script?

I know what to expect and I know what I want to deliver.

Brian OBrien wrote in post #1173897:

I want to run a ruby script within another ruby script in an
‘interactive’ mode like tcl/expect does.

PTY work on Linux :

PTY.spawn(“ruby a.rb”) do |read,write,pid|
begin
read.expect(rusername) { log “set user…” ; write.puts “a”}
read.expect(rpassword) { log “set passwd…” ; write.puts “b”}
read.expect(/completed/) {
log “OK !!!”
}
read.each { |o| log "log: "+o.chomp }
rescue Exception => e
Process.kill(“KILL”,pid)
ensure
end
end

If your command is a ruby script, you can use open3 ,
and flush stdout in child process :

==
require ‘open3’
Open3.popen3(“ruby.exe”,"-e",
"STDOUT.sync=true; [1,2,3,4,5,6].each { |g| puts g.to_s; sleep 1} "
) do |fin,fout,ferr|
p fout.gets.chomp until fout.eof?
end
puts “end.”