473,320 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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
4 5849

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Joe C | last post by:
I've written a console application and would like to isolate all screen output so that it will be easier to migrate the code to a GUI-type platform without modification to the base code. As a...
2
by: MLH | last post by:
Using A97, I have tables with 10-char text phone number fields to allow entry of xxxyyyyyyy phone numbers - where xxx is the 3-digit area code and yyyyyyy is the 7-digit phone number. I wish to...
6
by: Magix | last post by:
Hi, I want to use fprintf to write to a file. My question about the formatted output How can I format so that I can allocate certain width for each %s (Left-aignlied) ? Example: fprintf("%s...
2
by: lifeshortlivitup | last post by:
I had to create a program that allows the user to input a temp and then click on either the convert to fahrenheit or convert to celsius button and then display that result within the textbox that...
2
by: rufi | last post by:
hi group, I am new to C and using gcc compiler in Linux. I am having the following problems when using the printf() funtion to have the formatted output. Here r some things which i m trying...
6
by: Jojo | last post by:
Hi all, I was wondering how I can perform formatted output with C++ strings. For example, suppose I have in plain C: sprintf(C_string, "%5.2f %6d"); How can I do such a thing with C++...
4
by: keith | last post by:
I've been beating my head against this for a little while, so perhaps someone can help me out here? The code below should output exactly as follows (the hex data lines up in a fixed font): DATA...
0
by: suprodeep | last post by:
have a page for admin(admin.aspx). This would enter product name, image, category name and and long description in a formatted manner. The prod name, image, category name can be inputted to...
1
by: robnoper | last post by:
XP SP2, access and outlook 2003 I have a form with 3 command buttons on that when one is pressed it opens up a html email for the user to send. Two of the emails work fine and open with the full...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.