Testing whether a process has completed

On Fri, 17 Nov 2006, Matthew W. wrote:

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?

yes. it’s impossible on every platform in every language to do in a
reliable
and generic way.

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?

can you state exactly what you are trying to accomplish please: i
think
there is a fundemental problem with your design which you are not
considering:

  1. it might always be possible to send all input up front. in
    fact,
    this is the normal case, in general it’s not needed to know when
    a
    program is waiting for input, only that it will be at some point and
    you
    then simply send it all up from. eg
 IO.popen( cmd, 'r+' ) do |pipe|
   pipe.write the_precalculated_stdin
   pipe.close_write
   pipe.read
 end

this is, by far, the normal means of bi-directional communication
with
proccess.

  1. the input you send depends on the output of the program, in that
    case you
    will have this sort of logic
 IO.popen( cmd, 'r+' ) do |pipe|
   pipe.each do |stdout|
     case stdout
       when /foo/
         pipe.write 'you need foo'
       when /bar
         pipe.write 'you need bar'
       else
         pipe.write 'you need foobar'
     end
   end
 end

it seems like this problems your are having result from not realizing
that
input into any program, in any platform, is buffered by the os and your
program can merely send it when it finds it convenient - maybe i’m
wrong, but
it’s extrememly hard for me to imagine a scenario where one would
need to
know when a program required input - especially if one considers
multi-threaded or forking programs which may require multiple inputs at
once.

regards.

-a

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs