[Tutor] IPcount = 0 when used with subprocess.call (use something to convert to integer?)

Steven D'Aprano steve at pearwood.info
Tue May 8 07:14:10 CEST 2012


On Mon, May 07, 2012 at 08:09:55PM -0700, Rogelio wrote:

> import subprocess
> IPcount = subprocess.call(['wc -l file.txt | awk \'{print $1}\''], shell=True)
> print "You have",IPcount,"IP addresses that are alive."
> 
> I get the following output
>
> 46
> You have 0 IP addresses that are alive.
> 
> Why does IPcount not equal 46?  Is this what the stout is for?

Yes. The output of the call gets written to stdout. The return result of 
the call is 0 if the call succeeded and some other integer if it failed.


-- 
Steven



More information about the Tutor mailing list