Class: MysqlBackup::Pty
- Inherits:
-
Object
- Object
- MysqlBackup::Pty
- Defined in:
- lib/mysql_backup/pty.rb
Class Method Summary collapse
Class Method Details
.exec_pty(cmd, password) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/mysql_backup/pty.rb', line 8 def exec_pty(cmd, password) # $expect_verbose = true # NOTE uncomment to print output password = '' if password.nil? PTY.spawn(cmd) do |reader, writer, pid| begin reader.expect(/Enter password/, 1) do |line| writer.puts password end rescue puts "WARN: #{$!}" # TODO this can fail with unknown consequences puts reader.gets end begin while line = reader.gets # TODO detect errors we should act upon # raise line if line.strip.length > 1 end rescue Errno::EIO # EOF end end end |