If I use popen2, I need to write to one of the tuple parts. >>> f = os.popen2('ping 192.168.8.85 -c 100 > cap1.txt') >>> f[0].write('\x03')
Thank command works, but 'f[1]' is in read-only mode and I can't write to it. My command in the background is still not terminated. BTW I use Linux as OS. So, it doesn't work. Alan Gauld wrote: >> >>> 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? > > Alan G > _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor