How do you kill a PTY.spawn call in Ruby?

Posted by viatropos on Stack Overflow See other posts from Stack Overflow or by viatropos
Published on 2010-04-12T11:40:52Z Indexed on 2010/04/12 11:43 UTC
Read the original article Hit count: 305

Filed under:
|
|
|

If I run a command like this, using ruby's pty class, how do I kill it if I find a certain input string?

cmd = "appcfg.py update cdn"
PTY.spawn("#{cmd} 2>&1") do | input, output, pid |
  begin
    input.expect("Email:") do
      output.write("#{credentials[:username]}\n")
    end
    input.expect("Password:") do
      output.write("#{credentials[:password]}\n")
    end
    if input.gets == "SOMETHING"
      EXIT!
    end
  rescue Exception => e
    puts "GAE Error..."
  end
end

What is the right way to do that?

© Stack Overflow or respective owner

Related posts about ruby

Related posts about pty