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

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?

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

Edited 5 Years Ago by hondros: n/a

This question has already been answered. Start a new discussion instead.