displaying properly formatted output of ipconfig.exe

Discussion in 'Python' started by Joe Flynt, Nov 8, 2003.

  1. Joe Flynt

    Joe Flynt Guest

    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
    Joe Flynt, Nov 8, 2003
    #1
    1. Advertising

  2. "Joe Flynt" <> wrote in message
    news:...
    > 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
    Francis Avila, Nov 8, 2003
    #2
    1. Advertising

  3. In article <>,
    Francis Avila <> wrote:
    >
    >"Joe Flynt" <> wrote in message
    >news:...

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

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

    Cameron Laird <>
    Business: http://www.Phaseit.net
    Cameron Laird, Nov 9, 2003
    #3
  4. Joe Flynt

    Mark Hahn Guest

    "Cameron Laird" <> wrote in message
    news:...
    > In article <>,
    > Francis Avila <> wrote:
    > >
    > >"Joe Flynt" <> wrote in message
    > >news:...

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

    > .
    > .
    > .
    > 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>'
    Mark Hahn, Nov 9, 2003
    #4
  5. "Mark Hahn" <> wrote in message
    news:Jyirb.8919$7B2.5042@fed1read04...
    >
    > "Cameron Laird" <> wrote in message
    > news:...
    > > In article <>,
    > > Francis Avila <> wrote:
    > > >
    > > >"Joe Flynt" <> wrote in message
    > > >news:...

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

    > > .
    > > .
    > > .
    > > 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
    Francis Avila, Nov 9, 2003
    #5
  6. 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.

    --
    > ============================================================== <
    > | Wulfraed Dennis Lee Bieber KD6MOG <
    > | Bestiaria Support Staff <
    > ============================================================== <
    > Bestiaria Home Page: http://www.beastie.dm.net/ <
    > Home Page: http://www.dm.net/~wulfraed/ <
    Dennis Lee Bieber, Nov 9, 2003
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Neal Becker
    Replies:
    1
    Views:
    444
    Mike Driscoll
    May 1, 2008
  2. joblack
    Replies:
    2
    Views:
    1,338
    joblack
    Jun 7, 2010
  3. Todd Gardner

    How to run ipconfig in W2k?

    Todd Gardner, Jun 28, 2004, in forum: Ruby
    Replies:
    1
    Views:
    204
    gabriele renzi
    Jun 28, 2004
  4. Todd Gardner

    get same info as ipconfig?

    Todd Gardner, Jun 28, 2004, in forum: Ruby
    Replies:
    5
    Views:
    228
    Daniel Berger
    Jun 30, 2004
  5. Cosmic Cruizer

    TieRegistry with IPConfig

    Cosmic Cruizer, Apr 2, 2008, in forum: Perl Misc
    Replies:
    0
    Views:
    83
    Cosmic Cruizer
    Apr 2, 2008
Loading...

Share This Page