Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/ruby
- #coding: utf-8
- out_rd, out_wr = IO.pipe
- err_rd, err_wr = IO.pipe
- pid = fork
- if pid
- out_wr.close
- err_wr.close
- out_eof = false
- err_eof = false
- out_log = ''
- err_log = ''
- loop {
- fds = []
- fds << out_rd unless out_eof
- fds << err_rd unless err_eof
- break if fds.size < 1
- IO.select(fds)
- out = ''
- begin
- out = out_rd.read_nonblock(200)
- rescue Errno::EAGAIN
- ;
- rescue EOFError
- out_eof = true
- end
- err = ''
- begin
- err = err_rd.read_nonblock(200)
- rescue Errno::EAGAIN
- ;
- rescue EOFError
- err_eof = true
- end
- out_log << out
- err_log << err
- out_log = out_log[(out_log.size / 2) .. -1] if out_log.size > 5000
- err_log = err_log[(out_log.size / 2) .. -1] if err_log.size > 5000
- $stdout.write(out)
- $stderr.write(err)
- }
- pid, status = Process.wait2(pid)
- exitcode = status.exited? ? status.exitstatus : 128 + status.termsig
- if exitcode != 0 && ![9, 15].include?(status.termsig)
- unless fork
- text =
- "Команда: #{ARGV.join(' ')}\n" +
- "#{status.inspect}\n"
- text << "\nСообщения об ошибках:\n" + err_log if err_log.size > 0
- text << "\nВывод программы:\n" + out_log if out_log.size > 0
- exec "zenity", "--no-markup", "--error", "--title=Работа программы #{ARGV[0]} была завершена некорректно", "--text=" + text
- end
- end
- exit exitcode
- else
- out_rd.close
- err_rd.close
- $stdout.reopen out_wr
- $stderr.reopen err_wr
- exec *ARGV
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement