[Tutor] Redirecting output + calling dos commands with input tail

cino hilliard hillcino368@hotmail.com
Wed Jun 18 00:15:03 2003


Hi, Users


>From: Magnus Lyckå <magnus@thinkware.se>
>To: "cino hilliard" <hillcino368@hotmail.com>, tutor@python.org
>Subject: Re: [Tutor] Redirecting output + calling dos commands with  input 
>tail
>Date: Tue, 17 Jun 2003 23:52:34 +0200
>
>At 21:22 2003-06-17 +0000, cino hilliard wrote:
>>Hi,
>>First thanks Rick for asking the question.
>>
>>Magnus, maybe you can help me. The module below has functions that call 
>>dos commands.

>
>Sure! Can I bill you? :) Actually, I'm sure many people on

Yeah. go ahead. If it is reasonable. I am willing to pay for performance. 
:-).

>the list might help, and if you put it like that, others

Minor point to me. In a list, it is implicit that others can chime in. For 
what it is worth it was my intent
to inlist the help of others also.  otherwise, why would I copy them?

>might not bother, and I might not have the time.

>
>My instant reflection was that if you replace ".readlines()"
>with a simple ".read()" your printed output won't be messed
>up.
This is mind boggling. some comments I omitted from the post to my shell 
module are below
indicate I tried read() first.

# ................................................Suppose I wanted to 
examine some prime
# index primes in python. Then pypari("prime(prime(i)>i.txt") would place 
the ith
# PIP into the file t.txt. Then we can f=open("i","r") and let i = r.read() 
etc.
# the output into the >>> console is some times awkward and could be 
improved
# by using readline and printing one line at a time..................

Ok  I edited shell and used read() then did a reload(shell)  Thanks, Jeff!

def pycall(cmd):                             #call a dos file or command
    r,w = popen2(cmd)
    getit = r.read()                          #do not use readline
    print(getit)

and voila, pycall('dir')  gives
Volume in drive C has no label.
Volume Serial Number is E834-0F93

Directory of C:\Python23

06/17/2003  10:45 PM    <DIR>          .
06/17/2003  10:45 PM    <DIR>          ..
06/17/2003  01:34 PM                 0 (32)a
06/17/2003  01:34 PM                 0 (8x
05/21/2003  02:31 AM            35,763 10000!.txt
05/21/2003  02:38 AM               103 100000!.txt
05/21/2003  03:09 PM         5,565,821 1000000!.txt
[snip]
02/13/2003  03:37 AM               409 web.py
02/13/2003  03:38 AM               683 web.pyc
             101 File(s)     10,319,680 bytes
               9 Dir(s)  96,196,231,168 bytes free

Perfect!
pycall('dir>test.txt')
Also prints to file correctly.


>>>


>
>
>--
>Magnus Lycka (It's really Lyck&aring;), magnus@thinkware.se
>Thinkware AB, Sweden, www.thinkware.se
>I code Python ~ The Agile Programming Language
>


  3         3        3         3        3        6            2              
  (0^0)
2   +  13  +  33  +  43  =  49   =  7    =  343   = 117649

_________________________________________________________________
Protect your PC - get McAfee.com VirusScan Online  
http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963