From: Marko Schulz Date: 2001-04-24T21:06:31+09:00 Subject: [ruby-talk:14149] Re: threads and IO.popen questions On Tue, Apr 24, 2001 at 04:09:55PM +0900, Jean-Marc Beroud wrote: > Clemens Wyss wrote: > > the lobal variable $? contains the "exit code" of the last call: > > I.e.: > > output = IO.popen( "gzip -cd #{file}" ) > > if not($? == 0) then > > print ("Error #{output.read()}") > > end > > Doesn't work for me. The value of $? is not set on both cases. > This seems to be a bug. Example: > > $ rm test.gz > $ ruby -e'f = IO.popen( "gzip -cd test.gz" ); puts "code = <#{$?}>"' > test.gz: No such file or directory > code = <> > > $ echo "hello" | gzip - > test.gz > $ ruby -e'f = IO.popen( "gzip -cd test.gz" ); puts "code = <#{$?}>"' > code = <> I'm not sure about ruby (still new to it and didn't look at the source), but as far as I can remember Perl sets $? for pipes after closing it, since you cannot really tell what happened before. It seems to be the same with ruby: $ rm test.gz $ ruby -e'f = IO.popen( "gzip -cd test.gz" ); f.close; puts "code = <#{$?}>"' test.gz: No such file or directory code = <256> $ echo "hello" | gzip - > test.gz $ ruby -e'f = IO.popen( "gzip -cd test.gz" ); puts "code = <#{$?}>"' code = <> -- marko schulz Dieser Satz beinhalten drei Fehller.