[Tutor] os command

Kent Johnson kent37 at tds.net
Wed Oct 26 14:19:40 CEST 2005


Johan Geldenhuys wrote:
> I have script that calls a system command that I want to run for 5 minutes.
> """
> import os
> cmd = 'tcpdump -n -i eth0'
> os.system(cmd)
> """
> 
> I can start a timer after the cmd is issued, but I don't know how to 
> send a control signal to stop the command after I issued it. This is 
> normally from the shell  ^c.

This is problematic. In general there is no clean way to kill a thread in Python. The usual approach is to set a flag which the thread checks but this won't work for you.

A recent thread in comp.lang.python has some discussion and suggestions but it is inconclusive:
http://groups.google.com/group/comp.lang.python/browse_frm/thread/94281f5a797489b1/ebca44930a016f74?q=os.system+thread&rnum=5&hl=en#ebca44930a016f74

Kent
-- 
http://www.kentsjohnson.com



More information about the Tutor mailing list