ok someone please explain popen to me it runs subproccesses does this mean it can run programs from within my program? any help would be appreciated , there is not an easily spottable place that explains this. Thanks

Recommended Answers

All 6 Replies

These two code examples will illustrate the purpose and meaning of Popen ...

# save this code as calendar_may_2011.py 

import calendar

calendar.prmonth(2011, 5)

... now run this code ...

# calendar_may_2011_popen.py
# Popen (Pipe open) will open the 'pipe' containing the 
# standard output stream from a given Python program

import subprocess

# this will run the Python program in the working directory
# (or give full path of .py file so python.exe can find it)
cmd = "C:/Python27/python.exe calendar_may_2011.py"
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)

# allow the program to finish
p.wait()

# pipe the standard output to string s
s = p.stdout.read()

print(s)

'''you should see -->

      May 2011
Mo Tu We Th Fr Sa Su
                   1
 2  3  4  5  6  7  8
 9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31

'''

The old os.popen() has been deprecated since Python version 2.6

I dont get exactly what it does still is there no good documentation for it? and how come you post on all my posts do you live on daniweb and post on all newb stuff? lol im no complaining you have helped me out a bit , are you a forum shark?

so it opens the program through the internals of the computer?

ok I think I get popen a little better.

I dont get exactly what it does still is there no good documentation for it? and how come you post on all my posts do you live on daniweb and post on all newb stuff? lol im no complaining you have helped me out a bit , are you a forum shark?

Those two are probably the most knowledgeable people on python here ;D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.