testing whether a process has completed..

A

ara.t.howard

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.


2) 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top