[Tutor] Pipe variable to external command (fwd)

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Thu May 12 19:56:28 CEST 2005



---------- Forwarded message ----------
Date: Thu, 12 May 2005 11:31:57 -0600
From: Jeffrey Rice <jeffrice at finity.org>
To: Danny Yoo <dyoo at hkn.eecs.berkeley.edu>
Subject: Re: [Tutor] Pipe variable to external command


At 12:16 AM 5/12/2005, Danny Yoo wrote:
>######
> >>> child_out, child_in = popen2.popen2("wc")
> >>> child_in.write("hello world\nthis is a test\ngoodbye!\n")
> >>> child_in.close()
> >>> result = child_out.read()
> >>> child_out.close()
> >>> result
>'       3       7      36\n'
>######

Thanks for your help -- this is working, with a minor wrinkle I have not
cleared up yet.  I also need to read stderr, so I looked at the docs and it
seems that popen2.popen3 is the tool.

* * * *
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?

Jeff



*       *       *       *       *       *       *
Jeffrey Rice    ||     jeffrice at finity.org      ||  www.finity.org





More information about the Tutor mailing list