[Tutor] Pipe variable to external command (fwd)
Jeffrey Rice
jeffrice at finity.org
Thu May 12 20:17:20 CEST 2005
At 11:56 AM 5/12/2005, Danny Yoo wrote:
>* * * *
>CLAMAV_out, CLAMAV_in, CLAMAV_err= popen2.popen3(CLAMAV)
>CLAMAV_in.write(WORKING)
>CLAMAV_in.close()
>CLAM_RESULT=CLAMAV_out.read()
>CLAMAV_out.close()
>CLAM_ERR=CLAMAV_err.read()
>CLAMAV_err.close()
>* * * *
>
>CLAM_RESULT gives the correct reply, and stderr is 1. But CLAM_ERR is
>empty. This seems like it should be simple -- what am I missing?
I think I am messing this up! What I actually need is the exitcode of the
spawned command, which is why stderr did not contain the info I wanted. It
seems there is a new problem: to get the exitcode of the spawned process,
not the "shell" that contains it. I found this example on another list
that seems to address this problem:
http://www.ruby-talk.org/cgi-bin/scat.rb/ruby/ruby-talk/68786
As a work around, I end up calling popen3 like this:
Open3.popen3 ("/some/command/to/run ; echo $? 1>&2") { ... }
That ensures the exit code from /some/command/to/run will be the last
line of the standard error stream from Open3.popen3. Then I can just
pull that line off the output to get the return code.
Is there a more elegant way to get the exitcode off the child process, or
is this the "approved" method?
Jeff
* * * * * * *
Jeffrey Rice || jeffrice at finity.org || www.finity.org
More information about the Tutor
mailing list