How to identify a process ending in Ruby open3

If I run with:

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

How to determine if nikto is complete? It takes some time to complete the scan.

If something goes wrong, I suggest that I should periodically check for errors to see if anything is written?

Are there any decent documents that exist for open3? No, ruby-documents do not fit anywhere.

+3
source share
4 answers
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 are some good docs I found in googling: http://www.ensta.fr/~diam/ruby/online/ruby-doc-stdlib/libdoc/open3/rdoc/index.html

+3
source

* nix, SIGCHLD, . , , , .

, IO , EOF , , SIGPIPE, .

Ruby :

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

Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
  puts "stdout is:" + stdout.read
  puts "stderr is:" + stderr.read
end

Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
  while line = stderr.gets
    puts line
  end
end

http://blog.bigbinary.com/2012/10/18/backtick-system-exec-in-ruby.html

0

Source: https://habr.com/ru/post/1750752/


All Articles