Created
March 19, 2012 02:27
-
-
Save ox/2091114 to your computer and use it in GitHub Desktop.
A sinatra prototype that will run a pty session on the machine and show you a streamed response out to the web.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra' | |
require 'pty' | |
get '/' do | |
"<form action='/' method='POST'><input type='text' name='command'><input type='submit' value='run'></form>" | |
end | |
post '/' do | |
stream do |out| | |
out << "<html><body><pre>" | |
begin | |
PTY.spawn(params['command']) do |r, w, pid| | |
begin | |
r.each { |line| out << "#{line}\n" } | |
rescue Errno::EIO => e | |
out << "Errno:EIO, #{e.message}" | |
end | |
end | |
rescue Errno::ENOENT => e | |
out << "Errno::ENOENT, #{e.message}" | |
rescue PTY::ChildExited | |
out << "Process complete" | |
end | |
out << "</pre></body></html>" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment