Hi All,

Is it possible to flush the buffer of "popen2.Popen3(cmd)"after some time interval?

I am starting a server forever using the popen2 module. After some time the buffer gets full & it stops logging messages.

As a workaround to this, I am redirecting the output of 'cmd' to a file which solves the buffer problem but creates a new one.

Example: out = popen2.Popen3('./server > /log/log.txt')

Now because of the re direction two processes are started & out.pid returns the process id of the file redirection & I am not able to get the process id of "./server" process.

Any help would be greatly appreciated

Thanks

Have you tried sys.stdout.flush()? I don't know if that will work or not. Also, you want to begin to move over to the subprocess module. Theoretically, it should flush the buffer whenever you issue a read stdout using subprocess. I guess no one else has much to offer on this. A link to Hellman's subprocess PyMOTW http://blog.doughellmann.com/2007/07/pymotw-subprocess.html

Hey thanks for your help. I tried subprocess & it kind of worked.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.