Reputation: 73
i am write some code that suppose to take permission list from folder and compare the users\group list between this list to another list and if there is a fit between them he write the folder path so file. this is the code:
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)
when i test the code i get this error message: output = subprocess.check_output(['cacls', path]).splitlines() File "C:\Python33\lib\subprocess.py", line 586, in check_output raise CalledProcessError(retcode, process.args, output=output) subprocess.CalledProcessError: Command '['cacls', "['D:\\Scripting\\permissi on project'"]' returned non-zero exit status 123
any idea?
Upvotes: 4
Views: 7745
Reputation: 164
The message is saying that the command returns exit status 123, which indicates an error.
According to http://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx the status 123 indicates
The filename, directory name, or volume label syntax is incorrect.
Perhaps there is a problem with your directory name? There seems to be a space too much.
Upvotes: 3