473,405 Members | 2,185 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,405 software developers and data experts.

real time updating of popen, bufsize=0 problems

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

If I run it in cmd.exe it will print "1", wait 15sec, print "2", wait
15sec, print "3".

I tried doing it like this:

r, w, e = popen2.popen3('"C:/path/to/test.bat"',bufsize=0)
for line in r:
self.display.WriteText(line)

.... but get: ValueError: popen3() arg 3 must be -1

If I use -1, then it waits for the batch file to complete, and prints
out all 3 lines at once.
So I tried subprocess:
proc = subprocess.Popen('"C:/path/to/test.bat"', bufsize=0,
stdout=subprocess.PIPE)
for line in proc.stdout:
self.display.WriteText(line)

No error message, but no real time printing either.

info:
self.display is a wx.TextCtrl - not that it should matter,as
'WriteText()' behaves basically like 'print'
winXP pro SP2, python 2.5, wxPython 2.6.3.3
You help is appreciated.

Apr 6 '07 #1
4 2945
On Apr 6, 1:44 pm, "ianaré" <ian...@gmail.comwrote:
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

If I run it in cmd.exe it will print "1", wait 15sec, print "2", wait
15sec, print "3".

I tried doing it like this:

r, w, e = popen2.popen3('"C:/path/to/test.bat"',bufsize=0)
for line in r:
self.display.WriteText(line)

... but get: ValueError: popen3() arg 3 must be -1

If I use -1, then it waits for the batch file to complete, and prints
out all 3 lines at once.

So I tried subprocess:
proc = subprocess.Popen('"C:/path/to/test.bat"', bufsize=0,
stdout=subprocess.PIPE)
for line in proc.stdout:
self.display.WriteText(line)

No error message, but no real time printing either.

info:
self.display is a wx.TextCtrl - not that it should matter,as
'WriteText()' behaves basically like 'print'
winXP pro SP2, python 2.5, wxPython 2.6.3.3

You help is appreciated.
Hi,

I think this script on another post will help:

http://groups.google.com/group/comp....7e8e2a3?hl=en&

The 4 line code example (from Daniel) in one of the posts at this link
worked with your batch file:
http://www.velocityreviews.com/forum...em-output.html

Mike

Apr 6 '07 #2
On Apr 6, 3:22 pm, kyoso...@gmail.com wrote:
On Apr 6, 1:44 pm, "ianaré" <ian...@gmail.comwrote:
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
If I run it in cmd.exe it will print "1", wait 15sec, print "2", wait
15sec, print "3".
I tried doing it like this:
r, w, e = popen2.popen3('"C:/path/to/test.bat"',bufsize=0)
for line in r:
self.display.WriteText(line)
... but get: ValueError: popen3() arg 3 must be -1
If I use -1, then it waits for the batch file to complete, and prints
out all 3 lines at once.
So I tried subprocess:
proc = subprocess.Popen('"C:/path/to/test.bat"', bufsize=0,
stdout=subprocess.PIPE)
for line in proc.stdout:
self.display.WriteText(line)
No error message, but no real time printing either.
info:
self.display is a wx.TextCtrl - not that it should matter,as
'WriteText()' behaves basically like 'print'
winXP pro SP2, python 2.5, wxPython 2.6.3.3
You help is appreciated.

Hi,

I think this script on another post will help:

http://groups.google.com/group/comp....3a3c287e8e2a3?...

The 4 line code example (from Daniel) in one of the posts at this link
worked with your batch file:http://www.velocityreviews.com/forum...ossystem-outpu...

Mike
Thanks but it doesn't work. Still prints it out all at once. It is
supposed to print, then wait 15sec for the next line to print.

Apr 6 '07 #3
"ianaré" <ia****@gmail.comwrites:
hey all, I'm trying to get real time updates of batch file output.
[...]
So I tried subprocess:
proc = subprocess.Popen('"C:/path/to/test.bat"', bufsize=0,
stdout=subprocess.PIPE)
Instead of that:
for line in proc.stdout:
self.display.WriteText(line)
try that:

while True:
line = proc.stdout.readline()
if not line: break
self.display.WriteText(line)
When a file is used in a for loop it works like an iterator.
You can read details here (description of method ``next``):
http://docs.python.org/lib/bltin-file-objects.html

--
HTH,
Rob
Apr 6 '07 #4
On Apr 6, 3:59 pm, Rob Wolfe <r...@smsnet.plwrote:
"ianaré" <ian...@gmail.comwrites:
hey all, I'm trying to get real time updates of batch file output.

[...]
So I tried subprocess:
proc = subprocess.Popen('"C:/path/to/test.bat"', bufsize=0,
stdout=subprocess.PIPE)

Instead of that:
for line in proc.stdout:
self.display.WriteText(line)

try that:

while True:
line = proc.stdout.readline()
if not line: break
self.display.WriteText(line)

When a file is used in a for loop it works like an iterator.
You can read details here (description of method ``next``):http://docs.python.org/lib/bltin-file-objects.html

--
HTH,
Rob
Rob, you are the man =) thanks!

Apr 6 '07 #5

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

Similar topics

2
by: Gandalf | last post by:
Hi All! I don't know if this is a Python problem or not. Here is a snippet: import os TERM='\n\r\n\r' cmd = 'cu -l /dev/cuaa0 -s9600' pop = os.popen4(cmd,1) pop.write('AT'+TERM) # Ping modem
1
by: Jim Benson | last post by:
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...
1
by: Jonathan Hudgins | last post by:
When I try setting the bufsize on popen on windows I get the following error: output = os.popen( "ls", 'r', 1 ) ValueError: popen() arg 3 must be -1 The same is true for popen2, popen3 and...
2
by: I. Myself | last post by:
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...
13
by: bayer.justin | last post by:
Hi, I am trying to communicate with a subprocess via the subprocess module. Consider the following example: <subprocess.Popen object at 0x729f0> Here hey is immediately print to stdout of...
2
by: Greg Ercolano | last post by:
When I use os.popen(cmd,'w'), I find that under windows, the stdout of the child process disappears, instead of appearing in the DOS window the script is invoked from. eg: C:\type foo.py import...
2
by: Dmitry Teslenko | last post by:
Hello! I'm using os.popen to perform lengthy operation such as building some project from source. It looks like this: def execute_and_save_output( command, out_file, err_file): import os ...
1
by: Jean-Paul Calderone | last post by:
On Mon, 12 May 2008 17:35:44 -0700 (PDT), schickb <schickb@gmail.comwrote: Alas, you haven't actually closed src's standard input. Though you did close src.stdin, you didn't close the copy of it...
1
by: Mark Shewfelt | last post by:
Hello, I am attempting to use Popen() in a Windows service. I have a small Win32 .exe that I normally run through the os.popen2() function. I've written a class to work with the input and output...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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
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.