tags:

views:

89

answers:

3

If I run open with:

input, output,error = Open3.popen3 "nikto -host someip -port 80 -output xml"

How can I detect if nikto is done? It takes a while for the scan to complete.

If something goes wrong, I suppose I have to periodically check error to see if anything that been written?

Is there any decent docs that exist for open3? No, the ruby-docs are nowhere near decent.

+1  A: 
input, output, error = Open3.popen3 "nikto -host someip -port 80 -output xml"

if select([output], nil, nil, 0.1) and output.eof?
  # process exited and doesn't have output queued.
else
  # still running or has output not read yet.
end

Also, here is some good documentation I found by googling: http://www.ensta.fr/~diam/ruby/online/ruby-doc-stdlib/libdoc/open3/rdoc/index.html

Adrian
Thanks that solution does not work, but I am sure you put me on the right track.Those docs are the ruby-docs and it absolutely sucks.
@beavis - You probably think that the documentation "sucks" because it only contains documentation for the module. That is because the returned variables are not part of that library - they are IO objects, and all of their methods are documented at http://ruby-doc.org/core-1.9/classes/IO.html . There really isn't anything else to document about `Open3` without copying from that link. IO objects are pretty generic.
Adrian
I understand your point, but it sucks because they didn't bother to do anything else but show 2 simple examples. I guess they thought that no one would use it to add input during a long runtime, or even have a long runtime.Maybe I will use a nonblocking read and wait till EOF exception is raised, since the select example did not work.Thanks for your time.
+1  A: 
rogerdpack
+1  A: 

If you're using any *nix OS, your process will receive SIGCHLD when a subprocess exits. Depending on whether or not you have more than one subprocess at a time, this can be used to detect when it ends.

Also, the IO channels to the subprocess are implemented under the hood with pipes, so you will definitely get an EOF at the end of the output and possibly SIGPIPE when it shuts too.

In Ruby, installing a signal handler is just:

Signal.trap("CHLD") do
  Process.wait
  $child_died = true
end
dunedain289