I did yet another test:
[~]$ ./popen.rb
/etc/passwd
0
[~]$ cat popen.rb
#!/usr/bin/ruby -w
IO.popen("ls /etc/passwd") { |out|
out.each { |o| puts o }
}
puts $? >> 8
[~]$ ./popen3.rb
/etc/passwd
255
[~]$ cat popen3.rb
#!/usr/bin/ruby -w
require 'open3'
Open3.popen3("ls /etc/passwd") { |sin,out,err|
out.each { |o| puts o }
}
puts $? >> 8
As you can see, popen3 doesn't handle the exit status like popen does.
Is this a bug?
db
On Tue, Apr 08, 2003 at 02:28:41AM +0900, Daniel Bretoi wrote:
> I'd like to add that the exit status here is ALWAYS 255, no matter wht
> the command is.
>
> db
>
> On Tue, Apr 08, 2003 at 01:56:11AM +0900, Daniel Bretoi wrote:
> > Hi,
> >
> > For some reason the code I had posted earlier did not always work
> > correctly. I've now rearrange the code to work properly as far as
> > running, however, now I can't seem to capture the exit status.
> >
> > Help?
> >
> > def doit(command)
> > logfile = "test"
> > threads = []
> > fh = File.open(logfile,"w")
> > Open3.popen3(command) { |inp,out,err|
> >
> > threads << Thread.new(out) { |out|
> > out.each { |line| puts line; fh.print line }
> > }
> > threads << Thread.new(err) { |err|
> > err.each { |line| puts line; fh.print line }
> > }
> > threads.each { |t| t.join }
> > }
> > stat = $? >> 8
> > fh.close
> > stat
> > end
> >
> >
> > --
> > Apr 7 IBM announces System/360, 1964
> > Apr 7 Albert Hofmann synthesizes LSD in Switzerland, 1943
> > Apr 7 Alewives run, Cape Cod
> > Apr 7* Omer 10th day
>
> --
> Apr 7 IBM announces System/360, 1964
> Apr 7 Albert Hofmann synthesizes LSD in Switzerland, 1943
> Apr 7 Alewives run, Cape Cod
> Apr 7* Omer 10th day
--
Apr 7 IBM announces System/360, 1964
Apr 7 Albert Hofmann synthesizes LSD in Switzerland, 1943
Apr 7 Alewives run, Cape Cod
Apr 7* Omer 10th day