greg
11/21/2006 11:26:00 PM
watch out for security issues... there is no a sandbox in the latest
1.9 source ...
Can't you just write to the program's STDIN before it calls gets
anyways?
otherwise, you can monitor STDOUT for some kind of signal
alias_method :gets :__old_gets__
def gets
puts "WAITING_FOR_INPUT"
__old_gets__
end
I have not tried to do signal trapping, but instead of checking for a
special sequence on STDOUT you could try to send signals back and
forth.
This could be done by inserting a require statement, or by using a
launcher program.
Instead of creating a separate ruby process, you can run the other
programs from a launcher. In the launcher program just put
load #{user_program}
In the launcher program you can also modify $LOAD_PATH and ENV['PATH']
if you need.
One problem you may encounter with this approach is that the call stack
will have one more entry than expected- this could break things that do
not expect another level in caller(), or if the user program makes a
check like if $0 == __FILE__ before executing.