Skip to content

Commit 1411fcb

Browse files
committed
Use tempfile for stdin again
1 parent 4de2700 commit 1411fcb

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

lib/binaryen/command.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,25 @@ def command_path(cmd, ignore_missing)
3434
def spawn_command(*args, stderr: nil, stdin: nil)
3535
pid = nil
3636

37-
IO.pipe do |in_read, in_write|
38-
in_read.binmode
37+
Tempfile.create("binaryen-input") do |in_write|
3938
in_write.binmode
40-
in_write.sync = true
4139
in_write.write(stdin) if stdin
40+
in_write.close
4241

4342
Tempfile.create("binaryen-output") do |tmpfile|
4443
tmpfile.close
4544

4645
File.open(File::NULL, "w") do |devnull|
4746
IO.pipe do |err_read, err_write|
48-
pid = POSIX::Spawn.pspawn(*args, "--output=#{tmpfile.path}", in: in_read, out: devnull, err: err_write)
49-
in_read.close
47+
pid = POSIX::Spawn.pspawn(
48+
*args,
49+
"--output=#{tmpfile.path}",
50+
in_write.path,
51+
in: devnull,
52+
out: devnull,
53+
err: err_write,
54+
)
5055
err_write.close
51-
in_write.close
5256

5357
_, status = Process.waitpid2(pid)
5458
pid = nil

test/command_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def test_it_can_redirect_stderr
5959
end
6060

6161
stderr.rewind
62-
assert_equal("Fatal: Failed opening 'dfasdfasdfasdfsadf'\n", stderr.read)
62+
assert_includes(stderr.read, "Unexpected second positional argument")
6363
ensure
6464
stderr.close
6565
stderr.unlink

0 commit comments

Comments
 (0)