mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
matz
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1012 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
1b2d3f81ee
commit
4098e5861e
9 changed files with 57 additions and 33 deletions
24
lib/open3.rb
24
lib/open3.rb
|
@ -14,8 +14,8 @@ module Open3
|
|||
pr = IO::pipe
|
||||
pe = IO::pipe
|
||||
|
||||
pid = fork
|
||||
if pid == nil then # child
|
||||
pid = fork{
|
||||
# child
|
||||
pw[1].close
|
||||
STDIN.reopen(pw[0])
|
||||
pw[0].close
|
||||
|
@ -29,13 +29,21 @@ module Open3
|
|||
pe[1].close
|
||||
|
||||
exec(cmd)
|
||||
exit
|
||||
else
|
||||
pw[0].close
|
||||
pr[1].close
|
||||
pe[1].close
|
||||
pi = [ pw[1], pr[0], pe[0] ]
|
||||
_exit 127
|
||||
}
|
||||
|
||||
pw[0].close
|
||||
pr[1].close
|
||||
pe[1].close
|
||||
Thread.start do
|
||||
sleep 1
|
||||
Process.waitpid(pid)
|
||||
end
|
||||
pi = [ pw[1], pr[0], pe[0] ]
|
||||
if defined? yield
|
||||
return yield *pi
|
||||
end
|
||||
pi
|
||||
end
|
||||
module_function :popen3
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue