473,395 Members | 1,403 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,395 software developers and data experts.

simple popen question


Hi,

I use popen to run a binary executable.
A code snippit is below.
This part runs fine. I use readline()
to catch and print output from the binary
to the screen. The system obviously buffers
things. i.e. readline doesn't return after every
line of output from the executable.
Is there an easy way to turn off the buffering?
I tried adding the extra 'r' and a small bufsize
to the popen...no difference.

iFd = os.popen(self.sCmd + ' ' + sArgs)
# Run sCmd
while True:
line = iFd.readline()
if line == '':
# EOF found...break out.
break;

print '%s' % line[:-1]

iRet = iFd.close()

if (iRet != None):

print 'ERROR: error message'
Thanks,

Jim


Jul 18 '05 #1
1 1334
In article <ma**************************************@python.o rg>,
Jim Benson <jb*****@sextans.lowell.edu> wrote:

Hi,

I use popen to run a binary executable.
A code snippit is below.
This part runs fine. I use readline()
to catch and print output from the binary
to the screen. The system obviously buffers
things. i.e. readline doesn't return after every
line of output from the executable.
Is there an easy way to turn off the buffering?
I tried adding the extra 'r' and a small bufsize
to the popen...no difference.

iFd = os.popen(self.sCmd + ' ' + sArgs)

# Run sCmd
while True:
line = iFd.readline()
if line == '':
# EOF found...break out.
break;

print '%s' % line[:-1]

iRet = iFd.close()

if (iRet != None):

print 'ERROR: error message'

Jul 18 '05 #2

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

Similar topics

5
by: Sean Berry | last post by:
I am writing a little script to grep through a really long list of files and look for a certain phrase. I wanted to do something like this. li = os.popen("/usr/bin/grep -i %s...
2
by: Stuart McGraw | last post by:
When I run (Python 2.3.3) this script on a MS Windows 2000 machine: import os print "1st popen..." f = os.popen ("echo " + u"\u0054\u0045\u0053\u0054.txt") print f.read () print "2nd popen..."...
6
by: Robin Siebler | last post by:
I have a bunch of command line tests that I need to automate. I've run into too many bugs with the default Win2k command shell, so I need to either purchase 4NT or handle the logic and output...
5
by: damacy | last post by:
hello, everyone. i am trying to write a program which executes SQL commands stored in ..sql files. i wrote a function called psql() whose contents look like the following. .......
2
by: hubritic | last post by:
I am trying to set off commands on Windows 2003 from python. Specifically, I am trying to use diskpart with a script file (pointed to with path). cmd = p = Popen(cmd, shell=True) The script...
2
by: stephen_b | last post by:
Can someone let me know why this won't work? Thanks. '' '\n' Thanks. Stephen
3
by: Jesse | last post by:
Hi all, I have a problem using wget and Popen. I hope someone can help. -- Problem -- I want to use the command: wget -nv -O "dir/cpan.txt" "http://search.cpan.org" and capture all it's...
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...
15
by: Daniel Klein | last post by:
I'm trying to get popen to work on Windows. Here's a simplified example of what I'm trying to get working: I have a hw.c program as follows: #include <stdio.h> main() { printf ("Hello...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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,...

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.