|
1 | 1 | class Exec < Process |
2 | | - VERSION = "0.1.1" |
| 2 | + VERSION = "0.1.2" |
| 3 | + |
| 4 | + class Status < ::Process::Status |
| 5 | + getter stdout : String |
| 6 | + getter stderr : String |
| 7 | + |
| 8 | + {% if flag?(:win32) %} |
| 9 | + # :nodoc: |
| 10 | + def initialize(@exit_status : UInt32, @stdout : String, @stderr : String) |
| 11 | + end |
| 12 | + {% else %} |
| 13 | + # :nodoc: |
| 14 | + def initialize(@exit_status : Int32, @stdout : String, @stderr : String) |
| 15 | + end |
| 16 | + {% end %} |
| 17 | + end |
3 | 18 |
|
4 | 19 | def self.run(command : String, args = nil, env : Env = nil, clear_env : Bool = false, shell : Bool = true, |
5 | | - input : Stdio = Redirect::Inherit, output : Stdio = Redirect::Inherit, error : Stdio = Redirect::Inherit, chdir : Path | String? = nil) : Process::Status |
6 | | - status = new(command, args, env, clear_env, shell, input, output, error, chdir).wait |
| 20 | + input : IO = STDIN, output : IO = STDOUT, error : IO = STDERR, chdir : Path | String? = nil) : Status |
| 21 | + output_strio = String::Builder.new |
| 22 | + error_strio = String::Builder.new |
| 23 | + output_writer = IO::MultiWriter.new(output, output_strio) |
| 24 | + error_writer = IO::MultiWriter.new(error, error_strio) |
| 25 | + |
| 26 | + status = new(command, args, env, clear_env, shell, input, output_writer, error_writer, chdir).wait |
7 | 27 | $? = status |
8 | | - status |
| 28 | + |
| 29 | + output_writer.close |
| 30 | + error_writer.close |
| 31 | + output.close unless output.in?(STDOUT, STDERR) |
| 32 | + error.close unless error.in?(STDOUT, STDERR) |
| 33 | + Status.new(status.@exit_status, output_strio.to_s, error_strio.to_s) |
9 | 34 | end |
10 | 35 |
|
11 | 36 | def self.code(command : String, args = nil, env : Env = nil, clear_env : Bool = false, shell : Bool = true, |
|
0 commit comments