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

Discussion in 'Python' started by Robin Siebler, Sep 13, 2004.

  1. 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.popen4() 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!
     
    Robin Siebler, Sep 13, 2004
    #1
    1. Advertising

  2. On Sun, 2004-09-12 at 18:52, Robin Siebler wrote:
    > And how, exactly, do I *use* popen4()?


    import os
    command = 'ls -al nonexistent'
    fin, fout = os.popen4(command)
    # 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
     
    Mark McEahern, Sep 13, 2004
    #2
    1. Advertising

  3. Robin Siebler wrote:
    > 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.


    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.

    > 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.popen4() and
    > popen2.popen4()(did I miss any?)?


    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
     
    Daniel Dittmar, Sep 13, 2004
    #3
  4. Robin Siebler

    Jaime Wyant Guest

    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
    <> wrote:
    > 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.popen4() 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
    >
     
    Jaime Wyant, Sep 13, 2004
    #4
  5. Re: Python or 4NT? With a question or two about popen()

    * Jaime Wyant (2004-09-13 14:56 +0200)
    > 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 [...]


    Cryptic compared to Python syntax but a lot more readable than Windows
    cmd.exe syntax.

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


    * Advanced Bash-Scripting Guide
    http://www.tldp.org/LDP/abs/html/index.html
    http://personal.riverusers.com/~thegrendel/abs-guide-2.8.tar.bz2
    http://www.tldp.org/LDP/abs/abs-guide.pdf

    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
     
    Thorsten Kampe, Sep 13, 2004
    #5
  6. Re: Python or 4NT? With a question or two about popen()

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



    I tried IPython some time ago, but it didn't quite work properly on
    Windows. Has that been fixed?
     
    Robin Siebler, Sep 13, 2004
    #6
  7. Robin Siebler

    Aahz Guest

    In article <>,
    Robin Siebler <> wrote:
    >
    >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.


    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 () <*> http://www.pythoncraft.com/

    "A foolish consistency is the hobgoblin of little minds, adored by little
    statesmen and philosophers and divines." --Ralph Waldo Emerson
     
    Aahz, Sep 13, 2004
    #7
    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. nanda
    Replies:
    0
    Views:
    436
    nanda
    Jul 18, 2006
  2. Stephen Boulet

    popen and two-way communication

    Stephen Boulet, Oct 18, 2004, in forum: Python
    Replies:
    4
    Views:
    3,158
  3. GenxLogic
    Replies:
    3
    Views:
    1,290
    andrewmcdonagh
    Dec 6, 2006
  4. File.popen/IO.popen

    , May 20, 2006, in forum: Ruby
    Replies:
    1
    Views:
    233
    Robert Klemme
    May 20, 2006
  5. James Smith
    Replies:
    18
    Views:
    291
Loading...

Share This Page