From: Gennady Date: 2003-11-25T07:27:00+09:00 Subject: Re: Exit status on cmd executed via popen() Try variable $?, it holds the status of the last executed command. Works for commands executed with 'system', I think it is valid for popen as well. Gennady. Garance A Drosihn wrote: > Sometimes I write ruby scripts to filter the output of some > other command. So I write something like: > > cmdout = IO.popen(somecmd, "r") > cmdout.each_line {|aline| > # Do Stuff... > } > cmdout.close > > Is there any way to find out what the exit status was from > the command given to popen? It would be nice to have some > method that I could use like: > > if cmdout.popen_exit_status != 0 > # Do Error-processing stuff > end > > which could be done after reading all the lines, but before > the call to 'close'. > > Or do I need to do something more complicated than 'popen' > if I need to know the exit code from that command? >