This repository has been archived by the owner on Feb 7, 2018. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Save both STDOUT and STDERR when possible
Create an Output object that stores the returned output and error streams from the executed commands. Because only Process.spawn and Posix.spawn use pipes like this, they are the only two Runners that can handle capturing both STDOUT and STDERR. The PopenRunner can only handle one pipe, and backticks can only report on STDOUT.
- Loading branch information
Jon Yurek
committed
Sep 25, 2015
1 parent
2a89b71
commit ed4b3ab
Showing
18 changed files
with
186 additions
and
69 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
module Cocaine | ||
class CommandLine | ||
class MultiPipe | ||
def initialize | ||
@stdout_in, @stdout_out = IO.pipe | ||
@stderr_in, @stderr_out = IO.pipe | ||
end | ||
|
||
def pipe_options | ||
{ out: @stdout_out, err: @stderr_out } | ||
end | ||
|
||
def output | ||
Output.new(@stdout_output, @stderr_output) | ||
end | ||
|
||
def read_and_then(&block) | ||
close_write | ||
read | ||
block.call | ||
close_read | ||
end | ||
|
||
private | ||
|
||
def close_write | ||
@stdout_out.close | ||
@stderr_out.close | ||
end | ||
|
||
def read | ||
@stdout_output = read_stream(@stdout_in) | ||
@stderr_output = read_stream(@stderr_in) | ||
end | ||
|
||
def close_read | ||
@stdout_in.close | ||
@stderr_in.close | ||
end | ||
|
||
def read_stream(io) | ||
result = "" | ||
while partial_result = io.read(8192) | ||
result << partial_result | ||
end | ||
result | ||
end | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class Cocaine::CommandLine::Output | ||
def initialize(output = nil, error_output = nil) | ||
@output = output | ||
@error_output = error_output | ||
end | ||
|
||
attr_reader :output, :error_output | ||
|
||
def to_s | ||
output.to_s | ||
end | ||
end |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require 'spec_helper' | ||
|
||
describe Cocaine::CommandLine::Output do | ||
it 'holds an input and error stream' do | ||
output = Cocaine::CommandLine::Output.new(:a, :b) | ||
expect(output.output).to eq :a | ||
expect(output.error_output).to eq :b | ||
end | ||
|
||
it 'calls #to_s on the output when you call #to_s on it' do | ||
output = Cocaine::CommandLine::Output.new(:a, :b) | ||
expect(output.to_s).to eq 'a' | ||
end | ||
end |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.