Module: Chef::ShellOut::Windows

Included in:
Chef::ShellOut
Defined in:
lib/chef/shell_out/windows.rb

Instance Method Summary collapse

Instance Method Details

#read_stderr(stderr) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
# File 'lib/chef/shell_out/windows.rb', line 84

def read_stderr(stderr)
  return nil if @finished_stderr
  if chunk = stderr.sysread(8096)
    @stderr << chunk
  else
    @finished_stderr = true
  end
rescue EOFError
  @finished_stderr = true
rescue Errno::EAGAIN
end

#read_stdout(stdout) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/chef/shell_out/windows.rb', line 72

def read_stdout(stdout)
  return nil if @finished_stdout
  if chunk = stdout.sysread(8096)
    @stdout << chunk
  else
    @finished_stdout = true
  end
rescue EOFError
  @finished_stdout = true
rescue Errno::EAGAIN
end

#run_commandObject

– Missing lots of features from the UNIX version, such as environment, cwd, etc.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/chef/shell_out/windows.rb', line 33

def run_command
  # win32 open4 is really just open3.
  Open3.popen3(@command) do |stdin,stdout,stderr|
    @finished_stdout = false
    @finished_stderr = false
    stdin.close
    stdout.sync = true
    stderr.sync = true

    # TBH, I really don't know what this will do when it times out.
    # However, I'm powerless to make windows have non-blocking IO, so
    # thread party it is.
    Timeout.timeout(timeout) do
      out_reader = Thread.new do
        loop do
          read_stdout(stdout)
          break if @finished_stdout
        end
      end
      err_reader = Thread.new do
        loop do
          read_stderr(stderr)
          break if @finished_stderr
        end
      end

      out_reader.join
      err_reader.join
    end
  end

  @status = $?

  self

rescue Timeout::Error
  raise Chef::Exceptions::CommandTimeout, "command timed out:\n#{format_for_exception}"
end