Class: Runner
- Inherits:
-
Object
- Object
- Runner
- Defined in:
- app/ports/runner.rb
Overview
Motiro - A project tracking tool
Copyright (C) 2006-2008 Thiago Arrais
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation; either version 3 of the License, or
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Instance Method Summary collapse
-
#initialize(process_creator = IO) ⇒ Runner
constructor
A new instance of Runner.
- #run(command, input = '', env = {}) ⇒ Object
Constructor Details
#initialize(process_creator = IO) ⇒ Runner
Returns a new instance of Runner.
20 21 22 |
# File 'app/ports/runner.rb', line 20 def initialize(process_creator=IO) @creator = process_creator end |
Instance Method Details
#run(command, input = '', env = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/ports/runner.rb', line 24 def run(command, input='', env={}) commons = {} env.each_key do |k| commons[k] = ENV[k] if ENV.has_key?(k) end ENV.update env process = @creator.popen(command, 'r+') begin process << input process.flush rescue #ignore i/o errors end env.each_key do |k| ENV.delete k end commons.each do |k, v| ENV[k] = v end result = process.read process.close return result end |