Skip to content

Commit

Permalink
First pass at childprocess integration, 18 features failing
Browse files Browse the repository at this point in the history
  • Loading branch information
msassak committed Dec 3, 2010
1 parent 5908786 commit 077396a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
1 change: 1 addition & 0 deletions features/output.feature
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@announce
Feature: Output

In order to specify expected output
Expand Down
28 changes: 21 additions & 7 deletions lib/aruba/process.rb
Original file line number Diff line number Diff line change
@@ -1,45 +1,59 @@
require 'background_process'
require 'childprocess'
require 'tempfile'

module Aruba
class Process
def initialize(cmd, timeout)
@cmd = cmd
#@cmd = cmd
@timeout = timeout

@out = Tempfile.new("aruba-out")
@err = Tempfile.new("aruba-err")

@process = ChildProcess.build(cmd)
@process.io.stdout = @out
@process.io.stderr = @err
end

def run!(&block)
@process = BackgroundProcess.run(@cmd)
@process.start
@process.poll_for_exit(10)
#@process = BackgroundProcess.run(@cmd)
yield self if block_given?
end

def stdin
@process.stdin
@process.io.stdin
end

def output
stdout + stderr
end

def stdout
@out.rewind
if @process
@stdout ||= @process.stdout.read
@stdout ||= @out.read
else
''
end
end

def stderr
@err.rewind
if @process
@stderr ||= @process.stderr.read
@stderr ||= @err.read
else
''
end
end

def stop
if @process
status = @process.wait(@timeout)
status && status.exitstatus
#status = @process.wait(@timeout)
#status && status.exitstatus
@process.stop(@timeout)
end
end
end
Expand Down

0 comments on commit 077396a

Please sign in to comment.