displaying properly formatted output of ipconfig.exe

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Joe Flynt

    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
  • Francis Avila

    #2
    Re: displaying properly formatted output of ipconfig.exe


    "Joe Flynt" <joe.flynt@mail .portland.co.uk > wrote in message
    news:601be7f8.0 311081449.24b3f 7e2@posting.goo gle.com...[color=blue]
    > 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.[/color]
    [color=blue]
    > #!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[/color]

    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

    Comment

    • Cameron Laird

      #3
      Re: displaying properly formatted output of ipconfig.exe

      In article <vqqu1p7s48ep05 @corp.supernews .com>,
      Francis Avila <francisgavila@ yahoo.com> wrote:[color=blue]
      >
      >"Joe Flynt" <joe.flynt@mail .portland.co.uk > wrote in message
      >news:601be7f8. 0311081449.24b3 f7e2@posting.go ogle.com...[/color]

      Comment

      • Mark Hahn

        #4
        Re: displaying properly formatted output of ipconfig.exe


        "Cameron Laird" <claird@lairds. com> wrote in message
        news:vqr3mnjhaf 137@corp.supern ews.com...[color=blue]
        > In article <vqqu1p7s48ep05 @corp.supernews .com>,
        > Francis Avila <francisgavila@ yahoo.com> wrote:[color=green]
        > >
        > >"Joe Flynt" <joe.flynt@mail .portland.co.uk > wrote in message
        > >news:601be7f8. 0311081449.24b3 f7e2@posting.go ogle.com...[/color]
        > .
        > .
        > .[color=green][color=darkred]
        > >> cmdpipe = os.popen("ipcon fig","r")
        > >> lines = cmdpipe.readlin es()
        > >> print lines[/color]
        > >
        > >You don't want to print a list of strings, you want to print each string[/color][/color]
        in[color=blue][color=green]
        > >a list....
        > >
        > > lines = cmdpipe.readlin es()
        > >- print lines
        > >+ for line in lines:
        > >+ print line[/color]
        > .
        > .
        > .
        > OR perhaps you want simply to print the output:
        > - lines = cmdpipe.readlin es()
        > - for line in lines:
        > - print line
        > + print cmdpipe.read()
        >[/color]

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


        Comment

        • Francis Avila

          #5
          Re: displaying properly formatted output of ipconfig.exe

          "Mark Hahn" <mark@hahnca.co m> wrote in message
          news:Jyirb.8919 $7B2.5042@fed1r ead04...[color=blue]
          >
          > "Cameron Laird" <claird@lairds. com> wrote in message
          > news:vqr3mnjhaf 137@corp.supern ews.com...[color=green]
          > > In article <vqqu1p7s48ep05 @corp.supernews .com>,
          > > Francis Avila <francisgavila@ yahoo.com> wrote:[color=darkred]
          > > >
          > > >"Joe Flynt" <joe.flynt@mail .portland.co.uk > wrote in message
          > > >news:601be7f8. 0311081449.24b3 f7e2@posting.go ogle.com...[/color]
          > > .
          > > .
          > > .[color=darkred]
          > > >> 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[/color][/color][/color]
          string[color=blue]
          > in[color=green][color=darkred]
          > > >a list....
          > > >
          > > > lines = cmdpipe.readlin es()
          > > >- print lines
          > > >+ for line in lines:
          > > >+ print line[/color]
          > > .
          > > .
          > > .
          > > OR perhaps you want simply to print the output:
          > > - lines = cmdpipe.readlin es()
          > > - for line in lines:
          > > - print line
          > > + print cmdpipe.read()
          > >[/color]
          >
          > 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>'
          >[/color]

          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

          Comment

          Working...