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

R

Robin Siebler

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
 
M

Mark McEahern

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
 
D

Daniel Dittmar

Robin said:
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
 
J

Jaime Wyant

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
 
T

Thorsten Kampe

* 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
 
R

Robin Siebler

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?
 
A

Aahz

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top