Method: RakeScript::Shell#raw_execute

Defined in:
lib/rake_script/shell.rb

#raw_execute(command_line, stdout:, stderr:) ⇒ Process::Status

Executes shell command and stream it’s output.

Parameters:

  • command_line (String)

    command line to execute.

  • stdout (Proc)

    each command output line will be passed to this proc.

  • stderr (Proc)

    each command error output line will be passed to this proc.

Returns:

  • (Process::Status)

    status object for command.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/rake_script/shell.rb', line 68

def raw_execute(command_line, stdout:, stderr:)
  Open3.popen3(command_line) do |_stdin_io, stdout_io, stderr_io, wait_thread|
    Thread.new do
      begin
        until (raw_line = stdout_io.gets).nil? do
          stdout.call(raw_line)
        end
      rescue IOError => _
        # command process was closed and it's ok
      end

    end
    Thread.new do
      begin
        until (raw_line = stderr_io.gets).nil? do
          stderr.call(raw_line)
        end
      rescue IOError => _
        # command process was closed and it's ok
      end
    end
    wait_thread.value
  end
end