2014-02-13 60 views
-1

我想弄清楚如何在python中編寫腳本,其中我用「ls」列出當前目錄的內容,然後將ls的結果放入列表中以便我可以執行與ls中的每個元素都有關。實際上,我首先嚐試在終端上執行此操作,然後使用python編寫腳本,但我甚至無法在終端中使用它。列表中的目錄內容

哦,我試着從LS輸出重定向到一個文件,但我似乎沒有權限這麼做:

>>> subprocess.call(["ls ", directory_expanded, " > ", "namesoutput.txt"]) 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "/usr/lib64/python2.6/subprocess.py", line 478, in call 
    p = Popen(*popenargs, **kwargs) 
    File "/usr/lib64/python2.6/subprocess.py", line 642, in __init__ 
    errread, errwrite) 
    File "/usr/lib64/python2.6/subprocess.py", line 1234, in _execute_child 
    raise child_exception 
OSError: [Errno 13] Permission denied 

回答