Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > real time updating of popen, bufsize=0 problems

Reply
Thread Tools

real time updating of popen, bufsize=0 problems

 
 
=?iso-8859-1?B?aWFuYXLp?=
Guest
Posts: n/a
 
      04-06-2007
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.

 
Reply With Quote
 
 
 
 
kyosohma@gmail.com
Guest
Posts: n/a
 
      04-06-2007
On Apr 6, 1:44 pm, "ianaré" <(E-Mail Removed)> wrote:
> 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

 
Reply With Quote
 
 
 
 
=?iso-8859-1?B?aWFuYXLp?=
Guest
Posts: n/a
 
      04-06-2007
On Apr 6, 3:22 pm, (E-Mail Removed) wrote:
> On Apr 6, 1:44 pm, "ianaré" <(E-Mail Removed)> wrote:
>
>
>
> > 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.

 
Reply With Quote
 
Rob Wolfe
Guest
Posts: n/a
 
      04-06-2007
"ianaré" <(E-Mail Removed)> writes:

> 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
 
Reply With Quote
 
=?iso-8859-1?B?aWFuYXLp?=
Guest
Posts: n/a
 
      04-06-2007
On Apr 6, 3:59 pm, Rob Wolfe <(E-Mail Removed)> wrote:
> "ianaré" <(E-Mail Removed)> writes:
> > 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!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Ok time to do a partition (system) back up, for real this time.suggestions please squirlchatr@yahoo.com Computer Support 2 04-22-2009 10:42 AM
Updating JTable Atomically - block data changes while updating. news.rcn.com Java 2 12-10-2007 11:49 AM
Is time.time() < time.time() always true? flamesrock Python 8 11-24-2006 06:51 AM
product of real and (integer)(after converted to real one) value - vhdl found fatal error senthil VHDL 5 01-24-2004 04:37 AM
Real time converted to Unix time Brian Perl Misc 1 08-29-2003 04:36 AM



Advertisments