[Tutor] os.system sending of break signals
alan.gauld at freenet.co.uk
Fri Oct 28 10:07:36 CEST 2005
> >>> f = os.popen('ping 192.168.8.85 -c 100 > cap2.txt')
> You will see that I send the output from the command to a file, because
> I want to test how stop the command before it reaches 100 pings.
> If I don't write the output to the file 'cap2.txt' and succeeds in
> closing 'f', all the data returned to 'f' will be lost.
You can read the output of popen into your program with
f.read(), but that will read all of the output after the program
has run. However I think you can readline() too to catch it
line by line. You can also write() data to f thus allowing you
to send your Ctrl-C.(You may need popen2 or even popen3
to do the simultaneous read//write bit. #Or better still use
the new subprocess module in v2.4)
Does that do what you need?
More information about the Tutor