By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,994 Members | 2,073 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,994 IT Pros & Developers. It's quick & easy.

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

P: n/a
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!
Jul 18 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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

Jul 18 '05 #2

P: n/a
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
Jul 18 '05 #3

P: n/a
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
<ro***********@palmsource.com> 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

Jul 18 '05 #4

P: n/a
* 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/~theg...de-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
Jul 18 '05 #5

P: n/a
> 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?
Jul 18 '05 #6

P: n/a
In article <95*************************@posting.google.com> ,
Robin Siebler <ro***********@palmsource.com> 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 (aa**@pythoncraft.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
Jul 18 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.