Re: [Tutor] Using Linux commands

Magnus Lycka magnus at thinkware.se
Wed Dec 10 17:49:26 EST 2003


> >>> os.system('slapadd -l ldif-file.txt')
> 
> It works! Thanks a lot!

But that won't transfer the ouput from your 
command into the python script.

if you do:

import os
file_list = os.popen('ls').readlines()

you will get the result of 'ls' into the
variable file_list, and can work with that
in Python.

If you need access to stdin and stderr as
well as stdout, it gets a little more
complicated, but it's certainly doable.

-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus at thinkware.se



More information about the Tutor mailing list