> Is what you want possible in another language? It might help
> clarify what you need...
I'm not sure, have never had to do this before
Oh well, it was worth a try...
>> - I am running a Ruby program from my Rails application using:
>>
>> > thread = Thread.new do
>> > IO.popen("ruby my_program.rb", "r+") do |pipe|
>> > while !pipe.eof
>> > NOW - I NEED TO KNOW HOW TO CHECK IF THE RUBY PROGRAM IS WAITING FOR INPUT
>>
>> ..i can read from it by reading and then checking if this returns 'nil';
>
> You mean this thread reading from pipe? Having two programs here
> confuses the issue somewhat.
yes - Thread created in Rails app is running external Roby program - and
needs to display output and know when its waiting for input
OK, with you so far then...
>
> If it
> is running as a separate process, I don't see how you could interrogate
> it from this process. It would have to prompt you for input, use
> some other channel (sockets?) to tell you, etc.
> Because you have done "ruby my_program.rb", that's in a shell running
> another copy of ruby. You can't really get at the internals even from
> the shell. Even Expect scripts rely on prompting.
So your saying that, when running a program from the command prompt, it
isn't possible to find out if the program is waiting for input from the
user or is just executing part of the program?
As a human, no, one cannot. Not in my experience, anyway. I suppose
one might look at the output of ps and see if it talks about IO, but
then you don't know if it is scribbling exciting things on the disk
or doing the IO that connects to you.
So how would you advise i go about trying to determine whether or not
the program is waiting for input? Should i wait for a certain time and
then try and write to the program?
Well, if you are invoking it as above, you have access to the source
so you can get it to prompt you for input.
There are exits North, East, and West.
>
But you have to *know* that the "OK> " is a prompt.
require 'semiotics' #
Actually, apart from Tcl escaping, it's mostly the interaction
that is the time consuming part of writing Expect scripts.
--
Posted via http://www.ruby-forum.com/\.
Hugh
···
On Fri, 17 Nov 2006, Matthew Williams wrote: