displaying properly formatted output of ipconfig.exe

Francis Avila francisgavila at yahoo.com
Sun Nov 9 13:12:25 EST 2003


"Mark Hahn" <mark at hahnca.com> wrote in message
news:Jyirb.8919$7B2.5042 at fed1read04...
>
> "Cameron Laird" <claird at lairds.com> wrote in message
> news:vqr3mnjhaf137 at corp.supernews.com...
> > In article <vqqu1p7s48ep05 at corp.supernews.com>,
> > Francis Avila <francisgavila at yahoo.com> wrote:
> > >
> > >"Joe Flynt" <joe.flynt at mail.portland.co.uk> wrote in message
> > >news:601be7f8.0311081449.24b3f7e2 at posting.google.com...
> > .
> > .
> > .
> > >> cmdpipe = os.popen("ipconfig","r")
> > >> lines = cmdpipe.readlines()
> > >> print lines
> > >
> > >You don't want to print a list of strings, you want to print each
string
> in
> > >a list....
> > >
> > >  lines = cmdpipe.readlines()
> > >- print lines
> > >+ for line in lines:
> > >+     print line
> > .
> > .
> > .
> > OR perhaps you want simply to print the output:
> > - lines = cmdpipe.readlines()
> > - for line in lines:
> > -     print line
> > + print cmdpipe.read()
> >
>
> OR, perhaps you want it to look right in a web page:
>
> #!C:\Python23\python.exe
> import os
> print "Content-type: text/html\r\n\r\n"
> cmdpipe = os.popen("ipconfig","r")
> print '<html><head><title>ipconfig</title></head><body>'
> lines = cmdpipe.readlines()
> for line in lines:
>   print line,'<br>'
> print '</body></html>'
>

Actually, I just realized a subtle problem with using the print statement in
(almost) all these examples (including my own).  Since the output already
includes newlines, and print appends a newline, you'll end up with doubled
newlines.  Perhaps just used the write() method of the file object of
interest?  Or, you could append a comma to all your print statements
(although this is bound to cause maintenance problems later).
--
Francis Avila





More information about the Python-list mailing list