473,403 Members | 2,366 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Why does bufsize=1 not work in subprocess.Popen ?

I read in the docs that "bufsize=1" causes line buffering. (for
subprocess.Popen)

The following tiny program launches an executable file and then receives
its output. That works, but I want to
receive each line as it is ouput, not all of the lines at termination,
which is what is happening.
-------------------------------------------------------
from subprocess import Popen, PIPE
from os import remove, sep

p = Popen("." + sep + "myprogram", stdout=PIPE, bufsize=1)

while(1):
line = p.stdout.readline() # get next line
print line,
if line.count("terminator"):
break
------------------------------------------------------
How can I get line buffering?

Mitchell Timin

--
I'm proud of http://ANNEvolve.sourceforge.net. If you want to write software,
or articles, or do testing or research for ANNEvolve, let me know.

Humans may know that my email address is: (but remove the 3 digit number)
zenguy at shaw666 dot ca
Apr 29 '06 #1
2 4425
In <V6R4g.89900$P01.79112@pd7tw3no>, I. Myself wrote:
I read in the docs that "bufsize=1" causes line buffering. (for
subprocess.Popen)

The following tiny program launches an executable file and then receives
its output. That works, but I want to
receive each line as it is ouput, not all of the lines at termination,
which is what is happening.


From the Python side you can only control Python's input buffer but not
the output buffer of the external program you are starting. I guess that
programs buffers its output.

Ciao,
Marc 'BlackJack' Rintsch
Apr 29 '06 #2
Marc 'BlackJack' Rintsch wrote:
In <V6R4g.89900$P01.79112@pd7tw3no>, I. Myself wrote:

I read in the docs that "bufsize=1" causes line buffering. (for
subprocess.Popen)

The following tiny program launches an executable file and then receives
its output. That works, but I want to
receive each line as it is ouput, not all of the lines at termination,
which is what is happening.


From the Python side you can only control Python's input buffer but not
the output buffer of the external program you are starting. I guess that
programs buffers its output.

Ciao,
Marc 'BlackJack' Rintsch

That makes sense. I remember now that someone told me that Windows
sends line-by-line only to the screen. To a pipe it sends buffers full.

Thanks,

Mitchell Timin

--
I'm proud of http://ANNEvolve.sourceforge.net. If you want to write software,
or articles, or do testing or research for ANNEvolve, let me know.

Humans may know that my email address is: (but remove the 3 digit number)
zenguy at shaw666 dot ca
Apr 29 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Darren Dale | last post by:
I'm a developer on the matplotlib project, and I am having trouble with the subprocess module on windows (Python 2.4.2 on winXP). No trouble to report with linux. I need to use _subprocess instead...
3
by: madpython | last post by:
playing with subprocess.Popen on Windows I stumbled into the following problem: Python 2.4.3 (#69, Mar 29 2006, 17:35:34) IDLE 1.1.3 >>> import subprocess >>>...
9
by: Clodoaldo Pinto Neto | last post by:
Output from the shell: $ set | grep IFS IFS=$' \t\n' Output from subprocess.Popen(): "IFS=' \t\n" Both outputs for comparison:
4
by: =?iso-8859-1?B?aWFuYXLp?= | last post by:
hey all, I'm trying to get real time updates of batch file output. Here is my batch file: @echo off echo 1 @ping 127.0.0.1 -n 2 -w 1500 nul echo 2 @ping 127.0.0.1 -n 2 -w 1500 nul echo 3
12
by: Eric_Dexter | last post by:
I am trying to modify a programming example and I am coming up with two problems... first is that I can't seem to pass along the arguments to the external command (I have been able to do that with...
9
by: Phoe6 | last post by:
Hi all, Consider this scenario, where in I need to use subprocess to execute a command like 'ping 127.0.0.1' which will have a continuous non- terminating output in Linux. # code # This...
4
by: zane.selvans | last post by:
Hi there, I've been banging my head against this for a day, and I can't take it anymore. It's probably a stupid error, but I don't see where. I'm trying to use Python to call an external...
12
by: bhunter | last post by:
Hi, I've used subprocess with 2.4 several times to execute a process, wait for it to finish, and then look at its output. Now I want to spawn the process separately, later check to see if it's...
5
by: thedsadude | last post by:
Hello, I'm launching a script as follows: <code> p = subprocess.Popen() p.wait() </code> If p.py writes to sys.stdout, then it is shown on the console.
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.