stdout not flushed before os.execvp()

T

Thomas Guettler

Hi,

I noticed, that sys.stout does not get flushed before the process is
replaced. The last print statements (before execvp()) disappear.

It only happens, if the output is redirected to a file (if sys.stdout is
not line buffered).

"""#testexec.py
import os
print "Messsage"
os.execvp("/bin/true", ["/bin/true"])
"""

===> python tmp/testexec.py
Messsage

===> python tmp/testexec.py > out ; cat out


Is this a bug or feature?

My version:
Python 2.4.2 (#1, May 2 2006, 08:28:01)
GCC 4.1.0 (SUSE Linux)] on linux2
 
D

dakman

If you wanted to make sure stdio was flushed you could always do...

sys.stdout.write("Message\n")
sys.stdout.flush()
 
F

Fulvio

|feature. the "exec" system call operates on a lower level than the
|stdio buffering system.

I did in this manner:

for exe in ('imap4', 'pop3'):
if exe in cfgfil[optsrv + '.protocol']:
exe = exe[:4]; exe = 'call_func = _call_' + exe.upper() \
+ '(setting)'
try:
exec exe
except ProtocolError:
call_func = '#ERROR 02 = Protocol failed with %s' %optsrv
break

exists it a different way to do it?

F
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top