467,926 Members | 1,471 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,926 developers. It's quick & easy.

displaying properly formatted output of ipconfig.exe

I'm try to display the output of ipconfig.exe to the web browser
using:
Apache/2.0.48 (Win32) mod_python/3.1.2b Python/2.3.2

but when I view http://server/cgi-bin/test.py i get the following
format of output:
['\r\n', 'Windows IP Configuration\r\n', '\r\n',
etc.

How do I get it to display the same output as if I had executed the
program in cmd.exe?

This is the source of test.py:

#!C:\Python23\python.exe
import os
print "Content-type: text/html\r\n\r\n"
cmdpipe = os.popen("ipconfig","r")
lines = cmdpipe.readlines()
print lines
Jul 18 '05 #1
  • viewed: 5573
Share:
4 Replies

"Joe Flynt" <jo*******@mail.portland.co.uk> wrote in message
news:60**************************@posting.google.c om...
but when I view http://server/cgi-bin/test.py i get the following
format of output:
['\r\n', 'Windows IP Configuration\r\n', '\r\n',
etc. #!C:\Python23\python.exe
import os
print "Content-type: text/html\r\n\r\n"
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
--
Francis Avila

Jul 18 '05 #2
In article <vq************@corp.supernews.com>,
Francis Avila <fr***********@yahoo.com> wrote:

"Joe Flynt" <jo*******@mail.portland.co.uk> wrote in message
news:60**************************@posting.google. com...

Jul 18 '05 #3

"Cameron Laird" <cl****@lairds.com> wrote in message
news:vq***********@corp.supernews.com...
In article <vq************@corp.supernews.com>,
Francis Avila <fr***********@yahoo.com> wrote:

"Joe Flynt" <jo*******@mail.portland.co.uk> wrote in message
news:60**************************@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 ina 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>'
Jul 18 '05 #4
"Mark Hahn" <ma**@hahnca.com> wrote in message
news:Jyirb.8919$7B2.5042@fed1read04...

"Cameron Laird" <cl****@lairds.com> wrote in message
news:vq***********@corp.supernews.com...
In article <vq************@corp.supernews.com>,
Francis Avila <fr***********@yahoo.com> wrote:

"Joe Flynt" <jo*******@mail.portland.co.uk> wrote in message
news:60**************************@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 ina 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

Jul 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Joe C | last post: by
6 posts views Thread by Magix | last post: by
6 posts views Thread by Jojo | last post: by
4 posts views Thread by keith | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.