【发布时间】:2013-12-23 12:53:35
【问题描述】:
我正在编写一些代码,假设从文件夹中获取权限列表,并将此列表与另一个列表之间的 users\group 列表进行比较,如果它们之间合适,他会编写文件夹路径 so 文件。 这是代码:
import subprocess
import sys
import os, pprint, sys
from sys import argv
script, FILENAME = argv ##get folder\file
## copy permissions list to temporary file function
def check_per(path): ##"check_per" copy permission list to string and compares
test=open('tempG','w')
dir = 'GroupList'
output = subprocess.check_output(['cacls', path]).splitlines()
test.write(output)
while (True):
d=readline()
if not d: break
d=d[0:len(d)-1:]
d=str(d)
while (True):
line=groups.readline()
line=line[0:len(line)-1:]
if not line: break
temp=d.find(line, 0, len(d))
if temp!=-1:
dest=open(dir+'/'+line+'.txt','a')
dest.write(path)
dest.close()
groups.seek(0)
temp= open('temp.txt','w') ##temporary folder from sub-folders path list
file=open('folders_list.txt', 'w') ##arrange path in
##making list of all sub folders under the chosen path
temp.write("%s" %[x[0] for x in os.walk(os.path.abspath(FILENAME))])
temp.close()
temp=open('temp.txt', 'r')
##arrange every path in separate line
while (True):
a=temp.read(1)
if not a: break
if a==',':file.write("\n")
else:file.write(a)
file.close()
file=open('folders_list.txt', 'r')
temp.close()
os.remove('temp.txt') ##remove temp file
groups=open('GroupList.txt','r') ###open the file that contain the groups list
dir = 'GroupList'
os.mkdir(dir) ##make new dir for groups files
## making text file for every group in new folder "grouplist"
while(True): ##make text file for every group
a=groups.readline()
if not a:break
a=a[0:len(a)-1:]+'.txt'
b=open(dir+'/'+a,'w')
b.close()
while (True): ##taking path from folders list and call "check_per"
path=file.readline()
if not path: break
path=path[0:len(path)-1:]
check_per(path)
当我测试代码时,我收到以下错误消息: 输出 = subprocess.check_output(['cacls', path]).splitlines() 文件“C:\Python33\lib\subprocess.py”,第 586 行,在 check_output 中 引发 CalledProcessError(retcode, process.args, output=output) subprocess.CalledProcessError: 命令 '['cacls', "['D:\\Scripting\\permissi on project'"]' 返回非零退出状态 123
有什么想法吗?
【问题讨论】:
-
你希望
check_output(['cacls', path])做什么?
标签: python