summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHo-Sheng Hsiao <hosheng.hsiao@gmail.com>2012-03-30 23:17:44 -0400
committerHo-Sheng Hsiao <hosh@opscode.com>2012-05-10 14:51:43 -0400
commit8181e60de4fc960b942de37fb8866389c483635e (patch)
treeac3b4364108447fff11b5d9834f829350c1de528
parent904ddb782ee87f70ac04634e232ef10f23948b1b (diff)
downloadmixlib-shellout-8181e60de4fc960b942de37fb8866389c483635e.tar.gz
[CHEF-2994][WINDOWS] Mixlib::ShellOut::Windows should push input into stdin
-rw-r--r--lib/mixlib/shellout/windows.rb5
-rw-r--r--spec/mixlib/shellout_spec.rb19
2 files changed, 15 insertions, 9 deletions
diff --git a/lib/mixlib/shellout/windows.rb b/lib/mixlib/shellout/windows.rb
index 00ebb2e..942f377 100644
--- a/lib/mixlib/shellout/windows.rb
+++ b/lib/mixlib/shellout/windows.rb
@@ -72,6 +72,11 @@ module Mixlib
#
process = Process.create(create_process_args)
begin
+ # Start pushing data into input
+ stdin_write << input if input
+
+ # Close pipe to kick things off
+ stdin_write.close
#
# Wait for the process to finish, consuming output as we go
diff --git a/spec/mixlib/shellout_spec.rb b/spec/mixlib/shellout_spec.rb
index 74b96ea..3f0800b 100644
--- a/spec/mixlib/shellout_spec.rb
+++ b/spec/mixlib/shellout_spec.rb
@@ -369,8 +369,7 @@ describe Mixlib::ShellOut do
end
end
- # FIXME: Add Windows support
- context "with an input", :unix_only => true do
+ context "with an input" do
subject { stdout }
let(:input) { 'hello' }
@@ -771,7 +770,7 @@ describe Mixlib::ShellOut do
end
end
- context 'with subprocess reading lots of data from stdin', :unix_only => true do
+ context 'with subprocess reading lots of data from stdin' do
subject { stdout.to_i }
let(:ruby_code) { 'STDOUT.print gets.size' }
let(:options) { { :input => input } }
@@ -805,11 +804,13 @@ describe Mixlib::ShellOut do
end
end
- context 'with subprocess piping lots of data through stdin, stdout, and stderr', :unix_only => true do
- let(:multiplier) { 20_000 }
- let(:expected_output_with) { lambda { |chr| (chr * multiplier) + "#{LINE_ENDING}" + (chr * multiplier) + "#{LINE_ENDING}" } }
+ context 'with subprocess piping lots of data through stdin, stdout, and stderr' do
+ let(:multiplier) { 20 }
+ let(:expected_output_with) { lambda { |chr| (chr * multiplier) + (chr * multiplier) } }
+
# Use regex to work across Ruby versions
- let(:ruby_code) { 'while(input = gets) do ( input =~ /^f/ ? STDOUT : STDERR ).puts input; end' }
+ let(:ruby_code) { "STDOUT.sync = STDERR.sync = true; while(input = gets) do ( input =~ /^f/ ? STDOUT : STDERR ).print input.chomp; end" }
+
let(:options) { { :input => input } }
context 'when writing to STDOUT first' do
@@ -862,7 +863,7 @@ describe Mixlib::ShellOut do
end
end
- context 'when subprocess pauses before reading from stdin', :unix_only => true do
+ context 'when subprocess pauses before reading from stdin' do
subject { stdout.to_i }
let(:ruby_code) { 'sleep 0.5; print gets.size ' }
let(:input) { 'c' * 1024 }
@@ -895,7 +896,7 @@ describe Mixlib::ShellOut do
pending 'when running under Windows', :windows_only => true
end
- context 'without input data', :unix_only => true do
+ context 'without input data' do
context 'with subprocess that expects stdin' do
let(:ruby_code) { %q{print STDIN.eof?.to_s} }