473,513 Members | 2,559 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

stdout not flushed before os.execvp()

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
3 2035
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
7333
by: MK | last post by:
I have a Win32 console application (SNMPUTIL.EXE) which listens to incoming SNMP messages: C:\>snmputil trap snmputil: listening for traps... When a trap is generated on a remote server, it...
7
2543
by: mikeSpindler | last post by:
I've seen it addressed in searching, but not specifically what is recommended to get around it. On Linux where I did my development all was fine. But then going to Solaris for the target I found...
0
2439
by: Roman Neuhauser | last post by:
Hello, I have a piece of code that gets run in a script that has its stdout closed: import sys sys.stdout = sys.stderr c = subprocess.Popen (..., stdin = subprocess.PIPE,
1
4811
by: s99999999s2003 | last post by:
hi i am using this code to run a ps command in unix def run(program, *args): pid = os.fork() if not pid: os.execvp(program, (program,) + args) return os.wait() run("ps", "-eo...
2
12967
by: noelloen | last post by:
hi, I have the following code, int ret; char ** vector; //vector = "ls" vector ="-al" ..... //fork a child ......
8
5903
by: Paul Edwards | last post by:
Is it permissible in C89 to do an "fclose(stdout)" and then exit, or is the C runtime library allowed to assume that stdout remains open and thus unconditionally do an fclose itself? Thanks. ...
1
8217
by: ohaqqi | last post by:
Hi guys, I'm still working on my shell. I'm trying to implement a function typefile that will take a command line input as follows: > type <file1> This command will implement a catenation of...
4
2283
by: lovecreatesbea... | last post by:
For example, in Bourne Shell both stdout and stderr can be re-directed to /dev/null, $ ./a.out 2>&1 /dev/null then is there any difference still?
2
6841
by: thanhnh | last post by:
Hi. I have to write a simple Shell with History feature. First, I get a string from command line. The command line is split into tokens. And then, I call fork ( ) to create a new process. The child...
0
7260
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7160
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7537
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7525
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5685
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4746
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
456
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.