Open3.popen3 $B$N=*N;=hM}(B

e$B$H$_$?$G$9!#e(B

Open3.popen3 e$B$,%3%^%s%I$Ne(B exec
e$B$K<:GT$7$?>l9g$K!"DL>o$N=*N;=hM}$r9T$J$Ce(B
e$B$F$7$^$$!"e(Bat_exit e$BEy$,<B9T$5$l$F$7$^$$$^$9!#e(B

% ruby -ropen3 -e ‘at_exit{p $$}; Open3.popen3("/bin/hogehoge"){|i,o,e|
puts o.read}’
30583 e$B"+e(B e$B;Re(B(e$BB9e(B?)e$B%W%m%;%9$N=PNOe(B
30581

e$B4JC1$K%Q%C%A$r:n$C$F$_$^$7$?!#e(B

e$B%(%i!<%a%C%;!<%8$N7A<0$,JQ$o$C$F$7$^$$$^$9$1$I!D!#e(B

— open3.rb.orig 2006-08-05 07:00:21.000000000 +0900
+++ open3.rb 2007-01-24 23:13:42.000000000 +0900
@@ -45,7 +45,12 @@
STDERR.reopen(pe[1])
pe[1].close

  • exec(*cmd)
  • begin
  • exec(*cmd)
  • rescue Exception => e
  • STDERR.puts e.inspect
  • exit!(1)
  • end
    }
    exit!(0)
    }

e$B$J$+$@$G$9!#e(B

At Wed, 24 Jan 2007 23:42:02 +0900,
e$B$H$_$?$^$5$R$me(B wrote in [ruby-dev:30181]:

Open3.popen3 e$B$,%3%^%s%I$Ne(B exec e$B$K<:GT$7$?>l9g$K!"DL>o$N=*N;=hM}$r9T$J$Ce(B
e$B$F$7$^$$!"e(Bat_exit e$BEy$,<B9T$5$l$F$7$^$$$^$9!#e(B

e$B$I$C$A$+$H$$$&$H!"e(Bfork/exece$B$N$J$$4D6-$G$b;H$($k$h$&$Ke(B
Process.spawne$B$r3HD%$7$?$$$H$3$G$9$,!#e(B

e$B%(%i!<%a%C%;!<%8$N7A<0$,JQ$o$C$F$7$^$$$^$9$1$I!D!#e(B

e$B$3$&$$$&$N$O$I$&$G$7$g$&!#e(B

Index: lib/open3.rb

— lib/open3.rb (revision 11540)
+++ lib/open3.rb (working copy)
@@ -65,7 +65,9 @@ module Open3
pe[1].close

  • at_exit {exit!(false)}
  • at_exit {raise $!}
    exec(*cmd)
    }
  •  exit!(0)
    
  •  exit!(true)
    
    }

e$B$H$_$?$G$9!#e(B

On Thu, 25 Jan 2007 00:36:51 +0900
Nobuyoshi N. [email protected] wrote:

e$B%(%i!<%a%C%;!<%8$N7A<0$,JQ$o$C$F$7$^$$$^$9$1$I!D!#e(B

e$B$3$&$$$&$N$O$I$&$G$7$g$&!#e(B

  • at_exit {exit!(false)}
  • at_exit {raise $!}
    exec(*cmd)
    }
  •  exit!(0)
    
  •  exit!(true)
    

e$B$3$l$@$H!"e(Bat_exit e$B$h$j$bA0$K<B9T$5$l$ke(B trap SIGEXIT
e$B$,F0$$$A$c$$$^$9!#e(B

e$B=*N;=hM}$r9T$J$o$J$$e(B abort()
e$B$,$"$l$PNI$$$h$&$J5$$,$7$F$-$^$7$?!#e(B
abort!() e$B$H$+!#e(B

e$B$$$d!"$=$3$^$G%(%i!<%a%C%;!<%8$K$3$@$o$i$J$/$F$b$$$$$s$G$9$1$Ie(B
(^^;

e$B$J$+$@$G$9!#e(B

At Fri, 26 Jan 2007 08:22:42 +0900,
e$B$H$_$?$^$5$R$me(B wrote in [ruby-dev:30194]:

  • at_exit {exit!(false)}
  • at_exit {raise $!}
    exec(*cmd)
    }
  •  exit!(0)
    
  •  exit!(true)
    

e$B$3$l$@$H!"e(Bat_exit e$B$h$j$bA0$K<B9T$5$l$ke(B trap SIGEXIT e$B$,F0$$$A$c$$$^$9!#e(B

e$B$J$k$[$I!#$G$"$l$Pe(B at_exit e$B$re(B trap SIGEXIT
e$B$K$9$l$P$I$&$G$7$g$&!#e(B

e$B=*N;=hM}$r9T$J$o$J$$e(B abort() e$B$,$"$l$PNI$$$h$&$J5$$,$7$F$-$^$7$?!#e(B
abort!() e$B$H$+!#e(B

e$B$"$C$F$b$$$$$+$b$7$l$^$;$s$M!#e(B

e$B$J$+$@$G$9!#e(B

At Fri, 26 Jan 2007 09:26:39 +0900,
Nobuyoshi N. wrote in [ruby-dev:30195]:

e$B$3$l$@$H!"e(Bat_exit e$B$h$j$bA0$K<B9T$5$l$ke(B trap SIGEXIT e$B$,F0$$$A$c$$$^$9!#e(B

e$B$J$k$[$I!#$G$"$l$Pe(B at_exit e$B$re(B trap SIGEXIT e$B$K$9$l$P$I$&$G$7$g$&!#e(B

at_exit
e$B$r$+$($k$s$8$c$J$/$F!"e(Btrape$B$r%G%U%)%k%H$KLa$7$F$*$1$P$h$5$=$&$G$9!#e(B
e$B$=$l$H!"e(BProcess.detache$B$,DI2C$5$l$F$k$N$GFs=Ee(Bforke$B$O$b$&ITMW$+$b!#e(B

Index: lib/open3.rb

— lib/open3.rb (revision 11551)
+++ lib/open3.rb (working copy)
@@ -51,6 +51,4 @@ module Open3
pid = fork{
# child

  •  fork{
    
  • grandchild

    pw[1].close
    STDIN.reopen(pw[0])
    @@ -65,13 +63,14 @@ module Open3
    pe[1].close
  •  trap("EXIT", "DEFAULT")
    
  •  at_exit {exit!(false)}
    
  •  at_exit {raise($!)}
    
    exec(*cmd)
    }
  •  exit!(0)
    
  • }

    pw[0].close
    pr[1].close
    pe[1].close

  • Process.waitpid(pid)

  • Process.detach(pid)
    pi = [pw[1], pr[0], pe[0]]
    pw[1].sync = true