displaying properly formatted output of ipconfig.exe

J

Joe Flynt

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
 
F

Francis Avila

Joe Flynt said:
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
 
C

Cameron Laird

.
.
.

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()

(There are other alternatives; these are likely to be of most interest.)
 
M

Mark Hahn

Cameron Laird said:
.
.
.
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>'
 
F

Francis Avila

Mark Hahn said:
string

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).
 
D

Dennis Lee Bieber

Francis Avila fed this fish to the penguins on Sunday 09 November 2003
10:12 am:
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).

Doesn't matter... if the output is going to a web browser as HTML, new
lines are not displayed -- they are white space that the browser
ignores.

To get each line on its own needs the newlines to be replaced with
<br> tags.

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top