Subprocess puzzle and two questions
Tim Roberts
timr at probo.com
Wed Nov 14 02:17:14 EST 2012
wrw at mac.com wrote:
>...
>However, if I try the same operation in the python interpreter using subprocess.Popen like so:
>
>>>> import subprocess
>>>> result = subprocess.Popen(['time', 'nslookup', 'www.es.net', '8.8.4.4'], shell = False, stdout = subprocess.PIPE, stderr = subprocess.PIPE).communicate()
>>>> print result
>('Server:\t\t8.8.4.4\nAddress:\t8.8.4.4#53\n\nNon-authoritative answer:\nwww.es.net\tcanonical name = www3.es.net.\nName:\twww3.es.net\nAddress: 128.55.22.201\n\n', ' 0.06 real 0.00 user 0.00 sys\n')
>
>And the timing information I'm after has been truncated to two digits after the decimal. It appears that Popen is applying a default format.
No, that's silly. A few minutes thought should have told you that. In
your standalone test, you are getting the "time" command that is built in
to bash. In the subprocess example, you've specified "shell = False", so
you are using the external "time" command (/usr/bin/time in my system), and
that command has a different output format. The csh "time" command is
different yet again.
>1) how can I recover that third digit from the subprocess?
Do you actually believe that the third decimal place has any meaning at
all? It doesn't.
--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the Python-list
mailing list