How do i execute shellscripts from python?

Wojtek Walczak gminick at hacker.pl
Fri Dec 13 09:09:54 EST 2002


Dnia Fri, 13 Dec 2002 13:30:35 GMT, Jocke B napisał(a):
> I've been looking at the net for this, but didn't find anything.
> Lets say i've made a bash-script that does some calculations, and then
> prints out a string. I want to execute this script from my pythoncode
> and then use the string that the bash script returned.
> Is it possible to do that?
You can use os.popen():

% python
[...]
>>> import os
>>> print os.popen.__doc__
popen(command [, mode='r' [, bufsize]]) -> pipe
Open a pipe to/from a command returning a file object.
>>> a = os.popen("/bin/date")
>>> print a.read()
Fri Dec 13 15:08:47 CET 2002

>>> a.close()
>>>

-- 
[ ] gminick (at) underground.org.pl  http://gminick.linuxsecurity.pl/ [ ]
[ "Po prostu lubie poranna samotnosc, bo wtedy kawa smakuje najlepiej." ]



More information about the Python-list mailing list