Python or 4NT? With a question or two about popen()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robin Siebler

    #1

    Python or 4NT? With a question or two about popen()

    I have a bunch of command line tests that I need to automate. I've
    run into too many bugs with the default Win2k command shell, so I need
    to either purchase 4NT or handle the logic and output processing with
    Python. I'm looking for experiences, comments, problems, etc.

    Also, I'm trying to figure out how to use popen(). To say that the
    documentation and expamples available for this is sparse would be the
    understatment of the century! I know that I want to use popen4() but
    what is the difference between os.popen4(), win32pipe.popen 4() and
    popen2.popen4() (did I miss any?)?

    And how, exactly, do I *use* popen4()? I figured out how to use
    popen(), but I haven't been too successfull with popen(). A good
    example would really come in handy! I have *5* Python books and not
    one has an example for anything other than popen()!

    Robin L. Siebler
    Software Test Engineer
    PalmSource
    ---------------------------------------
    Homer Simpson: But every time I learn something new, it pushes out
    something old! Remember that time I took a home wine-making course and
    forgot how to drive? Marge: That's because you were drunk! Homer
    Simpson: And how!
  • Mark McEahern

    #2
    Re: Python or 4NT? With a question or two about popen()

    On Sun, 2004-09-12 at 18:52, Robin Siebler wrote:[color=blue]
    > And how, exactly, do I *use* popen4()?[/color]

    import os
    command = 'ls -al nonexistent'
    fin, fout = os.popen4(comma nd)
    # I never futz with stdin.
    fin.close()
    output = fout.read()
    exitCode = fout.close()
    if exitCode:
    print 'Error running %(command)s:\n% (output)s' % locals()
    else:
    print 'Success running %(command)s:\n% (output)s' % locals()

    This may have minor syntactical errors or typos--since I'm not verifying
    it by running it. But mostly, the above pattern should work.

    Questions?

    // m

    Comment

    • Daniel Dittmar

      #3
      Re: Python or 4NT? With a question or two about popen()

      Robin Siebler wrote:[color=blue]
      > I have a bunch of command line tests that I need to automate. I've
      > run into too many bugs with the default Win2k command shell, so I need
      > to either purchase 4NT or handle the logic and output processing with
      > Python. I'm looking for experiences, comments, problems, etc.[/color]

      I'm using 4NT as my interactive shell and it's fine. But as soon as a
      script requires something more complex than an IF, I'm doing it in Python.
      [color=blue]
      > Also, I'm trying to figure out how to use popen(). To say that the
      > documentation and expamples available for this is sparse would be the
      > understatment of the century! I know that I want to use popen4() but
      > what is the difference between os.popen4(), win32pipe.popen 4() and
      > popen2.popen4() (did I miss any?)?[/color]

      At least in earlier versions of Python, os.popen* didn't worked when the
      script was being called from a service or a GUI program, as such
      programs had no 'console' and therefor no stdin and stdout.
      win32pipe.popen * fixed that.

      Daniel

      Comment

      • Jaime Wyant

        #4
        Re: Python or 4NT? With a question or two about popen()

        At the risk of being labeled a heretic, I'm gonna suggest cygwin. In
        particular, the bash shell is really well suited for running
        "automated" CLI tests. Be aware though that bash syntax is really
        cryptic and if you don't use it a lot, you'll find yourself thumbing
        through the manual quiet a bit.

        If you do decide to do bash, do a google on "advanced bash tutorial".
        That ought to point you to a really nice tutorial.

        HTH,
        jw

        On 12 Sep 2004 16:52:51 -0700, Robin Siebler
        <robin.siebler@ palmsource.com> wrote:[color=blue]
        > I have a bunch of command line tests that I need to automate. I've
        > run into too many bugs with the default Win2k command shell, so I need
        > to either purchase 4NT or handle the logic and output processing with
        > Python. I'm looking for experiences, comments, problems, etc.
        >
        > Also, I'm trying to figure out how to use popen(). To say that the
        > documentation and expamples available for this is sparse would be the
        > understatment of the century! I know that I want to use popen4() but
        > what is the difference between os.popen4(), win32pipe.popen 4() and
        > popen2.popen4() (did I miss any?)?
        >
        > And how, exactly, do I *use* popen4()? I figured out how to use
        > popen(), but I haven't been too successfull with popen(). A good
        > example would really come in handy! I have *5* Python books and not
        > one has an example for anything other than popen()!
        >
        > Robin L. Siebler
        > Software Test Engineer
        > PalmSource
        > ---------------------------------------
        > Homer Simpson: But every time I learn something new, it pushes out
        > something old! Remember that time I took a home wine-making course and
        > forgot how to drive? Marge: That's because you were drunk! Homer
        > Simpson: And how!
        > --
        > http://mail.python.org/mailman/listinfo/python-list
        >[/color]

        Comment

        • Thorsten Kampe

          #5
          Re: Python or 4NT? With a question or two about popen()

          * Jaime Wyant (2004-09-13 14:56 +0200)[color=blue]
          > At the risk of being labeled a heretic, I'm gonna suggest cygwin. In
          > particular, the bash shell is really well suited for running
          > "automated" CLI tests. Be aware though that bash syntax is really
          > cryptic [...][/color]

          Cryptic compared to Python syntax but a lot more readable than Windows
          cmd.exe syntax.
          [color=blue]
          > If you do decide to do bash, do a google on "advanced bash tutorial".
          > That ought to point you to a really nice tutorial.[/color]

          * Advanced Bash-Scripting Guide

          Find information, resources and relevant links for riverusers.com. This domain may be for sale.



          I'd consider IPython (state-of-the-art replacement for basic Python
          CLI) in "shell mode" ("This profile turns IPython into a lightweight
          system shell with python syntax").

          Thorsten

          Comment

          • Robin Siebler

            #6
            Re: Python or 4NT? With a question or two about popen()

            > I'd consider IPython (state-of-the-art replacement for basic Python[color=blue]
            > CLI) in "shell mode" ("This profile turns IPython into a lightweight
            > system shell with python syntax").[/color]


            I tried IPython some time ago, but it didn't quite work properly on
            Windows. Has that been fixed?

            Comment

            • Aahz

              #7
              Re: Python or 4NT? With a question or two about popen()

              In article <95c29a5e.04091 21552.af6bdba@p osting.google.c om>,
              Robin Siebler <robin.siebler@ palmsource.com> wrote:[color=blue]
              >
              >I have a bunch of command line tests that I need to automate. I've
              >run into too many bugs with the default Win2k command shell, so I need
              >to either purchase 4NT or handle the logic and output processing with
              >Python. I'm looking for experiences, comments, problems, etc.[/color]

              While I haven't done any Windows shell programming for years, I used to
              be a heavy 4DOS user (and I think I actually purchased 4NT at one
              point). These days, I wouldn't even consider 4NT for anything serious.
              --
              Aahz (aahz@pythoncra ft.com) <*> http://www.pythoncraft.com/

              "A foolish consistency is the hobgoblin of little minds, adored by little
              statesmen and philosophers and divines." --Ralph Waldo Emerson

              Comment

              Working...