473,614 Members | 2,328 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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!
Jul 18 '05 #1
6 1843
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(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

Jul 18 '05 #2
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.popen 4() 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
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.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

Jul 18 '05 #4
* 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
> 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
In article <95************ *************@p osting.google.c om>,
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**@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
Jul 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
1730
by: Alexander Schmolck | last post by:
Two smallish things that have been bugging me; I'm not sure whether they're actually broken or not, but anyway here it goes: 1. ``os.system`` (and co): Shouldn't ``os.system``'s signature really be ``os.system(cmd, arg1, arg2,...)`` rather than ``os.system(some_string)``? Otherwise ``some_string`` almost certainly will be constructed by something along the lines of ``os.system('convert %s %s' % (infile, outfile))`` which of course is...
2
4541
by: Xah Lee | last post by:
Python Doc Problem Example: os.system Xah Lee, 2005-09 today i'm trying to use Python to call shell commands. e.g. in Perl something like output=qx(ls) in Python i quickly located the the function due to its
16
3087
by: diffuser78 | last post by:
I want to write a python program and call OS specific commands in it. So basically, instead of typing in on the command line argument I want to have it in a python program and let it do the action. for example. in my program I would want to call the ssh feature like one does on the command line ssh Admin@192.168.2.10 .....etc How can I do this easily ?
0
240
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 413 open ( +1) / 3407 closed (+10) / 3820 total (+11) Bugs : 897 open ( -3) / 6167 closed (+18) / 7064 total (+15) RFE : 234 open ( +1) / 238 closed ( +2) / 472 total ( +3) New / Reopened Patches ______________________
7
1856
by: Jonathan Fine | last post by:
Hello My problem is that I want a Python 2.4 module on a server that is running Python 2.3. I definitely want to use the 2.4 module, and I don't want to require the server to move to Python 2.4. More exactly, I am using subprocess, which is new in Python 2.4. What I am writing is something like
24
6097
by: Joe Salmeri | last post by:
I just upgraded from Python 2.4.2 to Python 2.5.1 and have found some unexpected behavior that appears to be a bug in the os.stat module. My OS is Windows XP SP2 + all updates. I have several programs that have worked flawlessly on all previous Python versions for years and they are now producing incorrect results in the code that uses os.stat. Searching through the 2.5.1 release notes I found the following:
3
1851
by: mclaugb | last post by:
Hello ALl, I have a compiled program "conv.exe" that works as follows: ----------------------------- Please selection from the following options. press "h" for help, "p" for print, "r" for readfile. Enter your request now: .... -------------------- Is there a way to script python using the subprocess method to start this program "conv.exe" and then send a "r" to the command line to make it, say,
4
3942
by: Aidan | last post by:
Hi, I'm having a bit of trouble with a python script I wrote, though I'm not sure if it's related directly to python, or one of the other software packages... The situation is that I'm trying to create a system backup script that creates an image of the system, filters the output though gzip, and then uploads the data (via ftp) to a remote site.
10
1496
by: bruce | last post by:
hi... can someone point me to where/how i would go about calling a ruby app from a python app, and having the python app being able to get a returned value from the ruby script. something like test.py a = os.exec(testruby.rb)
0
8142
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8589
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8443
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7114
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5548
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4058
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4136
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1438
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.