By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,626 Members | 1,146 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,626 IT Pros & Developers. It's quick & easy.

stdout not flushed before os.execvp()

P: n/a
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
--
Thomas GŁttler, http://www.thomas-guettler.de/ http://www.tbz-pariv.de/
E-Mail: guettli (*) thomas-guettler + de
Spam Catcher: ni**************@thomas-guettler.de

Oct 17 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Thomas Guettler wrote:
Is this a bug or feature?
feature. the "exec" system call operates on a lower level than the
stdio buffering system.

</F>

Oct 17 '06 #2

P: n/a
If you wanted to make sure stdio was flushed you could always do...

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

Thomas Guettler wrote:
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
--
Thomas GŁttler, http://www.thomas-guettler.de/ http://www.tbz-pariv.de/
E-Mail: guettli (*) thomas-guettler + de
Spam Catcher: ni**************@thomas-guettler.de
Oct 17 '06 #3

P: n/a
On Wednesday 18 October 2006 00:25, Fredrik Lundh wrote:
|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
Oct 18 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.