Grokbase Groups Python tutor May 2005
FAQ

At 12:24 PM 5/12/2005, Danny Yoo wrote:
######
import popen2
process = popen2.Popen3(['wc'])
process.tochild.write("hello\nworld")
process.tochild.close()
process.fromchild.read()
' 1 2 11\n'
process.fromchild.close()
process.wait()
######
This is all well and good if the child exits with 0, but things get a
little funky if it doesn't.

For example, modifying the model to have clamdscan exit with 0:

######
import popen2
process = popen2.Popen3(['clamdscan','ham.test'])
process.tochild.close()
process.fromchild.read()
'ham.test: OK\n\n----------- SCAN SUMMARY -----------\nInfected files:
0\nTime: 0.098 sec (0 m 0 s)\n'
process.fromchild.close()
process.wait()
######

Now rewrite it to return an exit code of 1:

######
import popen2
process = popen2.Popen3(['clamdscan','eicar.test'])
process.tochild.write("hello\nworld")
process.tochild.close()
process.fromchild.read()
'eicar.test: Eicar-Test-Signature FOUND\n\n----------- SCAN SUMMARY
-----------\nInfected files: 1\nTime: 0.043 sec (0 m 0 s)\n'
process.fromchild.close()
process.wait()
256
######

Now for a exit code of 2:

######
import popen2
process = popen2.Popen3(['clamdscan','nonexistent.test'])
process.tochild.close()
process.fromchild.read()
'\n----------- SCAN SUMMARY -----------\nInfected files: 0\nTime: 0.004 sec
(0 m 0 s)\n'
process.fromchild.close()
process.wait()
512
######

In my fiirst example, clamdscan should return 1 when the EICAR string is
found -- process.wait() gets 256 instead.
In the second, clamdscan returns 2 if an error occurs, such as trying to
scan a non-existent file, but 512 is returned.

No doubt there is a reason why the exit code is getting multiplied by
256... ??? My search has not enlightened me, however.

Jeff


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

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 4 of 5 | next ›
Discussion Overview
grouptutor @
categoriespython
postedMay 12, '05 at 5:56p
activeMay 12, '05 at 11:10p
posts5
users2
websitepython.org

2 users in discussion

Danny Yoo: 3 posts Jeffrey Rice: 2 posts

People

Translate

site design / logo © 2022 Grokbase