473,734 Members | 6,098 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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\p ython.exe
import os
print "Content-type: text/html\r\n\r\n"
cmdpipe = os.popen("ipcon fig","r")
lines = cmdpipe.readlin es()
print lines
Jul 18 '05 #1
4 5876

"Joe Flynt" <jo*******@mail .portland.co.uk > wrote in message
news:60******** *************** ***@posting.goo gle.com...
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\p ython.exe
import os
print "Content-type: text/html\r\n\r\n"
cmdpipe = os.popen("ipcon fig","r")
lines = cmdpipe.readlin es()
print lines


You don't want to print a list of strings, you want to print each string in
a list....

lines = cmdpipe.readlin es()
- 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.go ogle.com...

Jul 18 '05 #3

"Cameron Laird" <cl****@lairds. com> wrote in message
news:vq******** ***@corp.supern ews.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.go ogle.com...

.
.
.
cmdpipe = os.popen("ipcon fig","r")
lines = cmdpipe.readlin es()
print lines


You don't want to print a list of strings, you want to print each string ina list....

lines = cmdpipe.readlin es()
- print lines
+ for line in lines:
+ print line

.
.
.
OR perhaps you want simply to print the output:
- lines = cmdpipe.readlin es()
- for line in lines:
- print line
+ print cmdpipe.read()


OR, perhaps you want it to look right in a web page:

#!C:\Python23\p ython.exe
import os
print "Content-type: text/html\r\n\r\n"
cmdpipe = os.popen("ipcon fig","r")
print '<html><head><t itle>ipconfig</title></head><body>'
lines = cmdpipe.readlin es()
for line in lines:
print line,'<br>'
print '</body></html>'
Jul 18 '05 #4
"Mark Hahn" <ma**@hahnca.co m> wrote in message
news:Jyirb.8919 $7B2.5042@fed1r ead04...

"Cameron Laird" <cl****@lairds. com> wrote in message
news:vq******** ***@corp.supern ews.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.go ogle.com... .
.
.
> cmdpipe = os.popen("ipcon fig","r")
> lines = cmdpipe.readlin es()
> print lines

You don't want to print a list of strings, you want to print each
string ina list....

lines = cmdpipe.readlin es()
- print lines
+ for line in lines:
+ print line

.
.
.
OR perhaps you want simply to print the output:
- lines = cmdpipe.readlin es()
- for line in lines:
- print line
+ print cmdpipe.read()


OR, perhaps you want it to look right in a web page:

#!C:\Python23\p ython.exe
import os
print "Content-type: text/html\r\n\r\n"
cmdpipe = os.popen("ipcon fig","r")
print '<html><head><t itle>ipconfig</title></head><body>'
lines = cmdpipe.readlin es()
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
3568
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 first step, I've created a variable: bool useConsole(true); then I trap all output like: if(useConsole){ cout << text; }
2
8292
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 display these as (xxx) yyy-yyyy. Trouble is, some telephone numbers are entered by users as only 7-digits. They omit the area code in many cases, understandably. They consider it redundant and its not necessary for them to dial it - in most cases,...
6
2999
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 %s %s %s, name, age, city, status); <-------------------><----------------><----------------><------------->
2
11198
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 says "user entered amount in F or C is equal to answer degrees F or C." I have the code written for the convert to Fahrenheit but do not understand how to get the converted temp to display in the text box along with the above desired text. Below is my...
2
2050
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 : The range of short int(which is signed by default) is -32768 to + 32767.
6
3683
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++ strings? Using a string stream and the << operator does not give me the formatting control like sprintf. Or did I miss something.... :-|
4
4657
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 0123456789abcdef0123456789abcdef 0123456789abcdef0123456789abcdef and the code does indeed do that when I use the fprintf() call. When I comment that line out and use the iostream line, I get gibberish. I guess I'm just not 'getting' C++...
0
983
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 database. However for long description i am using an html editor downloaded from net called cutesoft. Then i use server.htmlencode for entering the text inside the editor into the database (sql server 2000). This gets saved in the database. But plz send...
1
4588
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 colour and size formatted text but one of them just shows the html code in the body with no formatting. The vba code for the command button is as follows: Private Sub cmdUpdateEmail_Click() Dim HTMLReminderEmail As String Dim Subject As String...
0
8783
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9459
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9321
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9248
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9193
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6745
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3268
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.