FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Python os.popen examples?





akonvisher
Hi All.
Somebody can public examples of operand Python os.popen examples?
SonLight
Popen is most commonly used in python to get data between different processes. Python 3 has greatly improved methods for process control, so I suggest if that's your application you check the basic python docs and then ask questions about anything you are uncertain of. If that doesn't point you in the right direction for what you need, your application may be of interest to others, or if it's interfacing with something written in another language, someone might take pity and help you anyway.
amagard
Here is a simple example, found in www.pythonforbeginners.com:


Code:
import subprocess
p = subprocess.Popen(["echo", "hello world"], stdout=subprocess.PIPE)
print p.communicate()
>>>('hello world\n', None)


You can do much more with popen, like having two processes talking to each other:

Code:

output=`dmesg | grep hda`
# becomes
p1 = Popen(["dmesg"], stdout=PIPE)
p2 = Popen(["grep", "hda"], stdin=p1.stdout, stdout=PIPE)
p1.stdout.close()  # Allow p1 to receive a SIGPIPE if p2 exits.
output = p2.communicate()[0]


This example is taken from docs.python.org, description of the subprocess module, see chapter 17.1.4.2
astrobyte
Well os.popen, like os.system, is used to run system commands but the main difference is that u can save the output of os.popen as a variable using read function like so:

myVar = os.popen("command").read()

Ex:

directories = os.popen("ls").read()
johans
I dont know this kind of technology..

I will do also research on this so that i have information perhaps i am interested to know also on this.
Related topics
Bluetooth worm targets Mac OS X
Simple python
problem with python's os.mkdir in cgi test
Python execute External Application. How?
launching shell scripts from jython/python
Jython: os.chdir()
Python....
website in python
DOS OS installation.
Thinking about creating my own OS
How can I run external program in python
Network OS /Real Time OS
Advice on switching OS [Windows --> UNIX? Linux?]
Python - Using files
Python: Slicing
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.