Skip to content

Commit 5fd442b

Browse files
committed
fix: IO::MultiWriter not add STDOUT twice
1 parent 252371a commit 5fd442b

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
dependencies:
1111
exec:
1212
github: initdc/exec.cr
13-
version: 0.2.0
13+
version: 0.2.1
1414
```
1515
1616
2. Run `shards install`

shard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: exec
2-
version: 0.2.0
2+
version: 0.2.1
33

44
authors:
55
- initdc <initd@outlook.com>

spec/exec_spec.cr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ describe Exec do
2525
Exec.run("uname").should eq "Linux\n"
2626
end
2727

28+
it "print once Linux\n" do
29+
Exec.run("uname", output: STDOUT).should eq "Linux\n"
30+
end
31+
2832
it "looks like ruby Open3 when bad" do
2933
r = Exec.run("echo good && echo bad >&2 && exit 1")
3034
case r

src/exec.cr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class Exec < Process
2-
VERSION = "0.2.0"
2+
VERSION = "0.2.1"
33

44
class IO
55
class MultiWriter < ::IO::MultiWriter
@@ -19,20 +19,20 @@ class Exec < Process
1919
output_writer = if output.is_a?(Redirect)
2020
output == Redirect::Close ? output : Exec::IO::MultiWriter.new(STDOUT, output_strio)
2121
else
22-
Exec::IO::MultiWriter.new(STDOUT, output, output_strio)
22+
output != STDOUT ? Exec::IO::MultiWriter.new(STDOUT, output, output_strio) : Exec::IO::MultiWriter.new(STDOUT, output_strio)
2323
end
2424

2525
error_writer = if error.is_a?(Redirect)
2626
error == Redirect::Close ? error : Exec::IO::MultiWriter.new(STDERR, error_strio)
2727
else
28-
Exec::IO::MultiWriter.new(STDERR, error, error_strio)
28+
error != STDERR ? Exec::IO::MultiWriter.new(STDERR, error, error_strio) : Exec::IO::MultiWriter.new(STDERR, error_strio)
2929
end
3030

3131
status = new(command, args, env, clear_env, shell, input, output_writer, error_writer, chdir).wait
3232
$? = status
3333

34-
output.close unless output.is_a?(Redirect)
35-
error.close unless error.is_a?(Redirect)
34+
output.close unless output.is_a?(Redirect) || output == STDOUT
35+
error.close unless error.is_a?(Redirect) || error == STDERR
3636
output_strio.close
3737
error_strio.close
3838

0 commit comments

Comments
 (0)