472,784 Members | 996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,784 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 5811

"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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.