mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/open3.rb (Open3#popen3): use Thread.detach instead of
double-fork, so that the exit status can be obtained. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@26783 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
15548a5a24
commit
7d51a12d9d
3 changed files with 23 additions and 20 deletions
32
lib/open3.rb
32
lib/open3.rb
|
@ -56,39 +56,37 @@ module Open3
|
|||
|
||||
pid = fork{
|
||||
# child
|
||||
fork{
|
||||
# grandchild
|
||||
pw[1].close
|
||||
STDIN.reopen(pw[0])
|
||||
pw[0].close
|
||||
pw[1].close
|
||||
STDIN.reopen(pw[0])
|
||||
pw[0].close
|
||||
|
||||
pr[0].close
|
||||
STDOUT.reopen(pr[1])
|
||||
pr[1].close
|
||||
pr[0].close
|
||||
STDOUT.reopen(pr[1])
|
||||
pr[1].close
|
||||
|
||||
pe[0].close
|
||||
STDERR.reopen(pe[1])
|
||||
pe[1].close
|
||||
pe[0].close
|
||||
STDERR.reopen(pe[1])
|
||||
pe[1].close
|
||||
|
||||
exec(*cmd)
|
||||
}
|
||||
exit!(0)
|
||||
exec(*cmd)
|
||||
}
|
||||
|
||||
pw[0].close
|
||||
pr[1].close
|
||||
pe[1].close
|
||||
Process.waitpid(pid)
|
||||
waiter = Process.detach(pid)
|
||||
pi = [pw[1], pr[0], pe[0]]
|
||||
result = pi + [waiter]
|
||||
pw[1].sync = true
|
||||
if defined? yield
|
||||
begin
|
||||
return yield(*pi)
|
||||
return yield(*result)
|
||||
ensure
|
||||
pi.each{|p| p.close unless p.closed?}
|
||||
waiter.join
|
||||
end
|
||||
end
|
||||
pi
|
||||
result
|
||||
end
|
||||
module_function :popen3
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue