返回非零退出状态123

4

我正在编写一些代码,旨在从文件夹中获取权限列表并比较该列表中的用户/组列表与另一个列表。如果它们匹配,我将在文件中写入文件夹路径。 以下是代码:

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)

当我测试代码时,出现以下错误信息: 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'"]' 的返回值不是零(非零状态码123),有什么想法吗?

你期望 check_output(['cacls', path]) 做什么? - aIKid
1个回答

3

当我尝试在同一文件夹中的另一个脚本中单独运行per_check时,它可以正常工作。但是当我在这个脚本中调用她时,我会收到这个消息。 - Tzuriel Yamin
你检查过发送给 check_per 的路径是否正确吗?也许它被某种方式搞乱了? - Johannes
谢谢,那就是问题所在,我应该在发送给函数之前清理一些残留物。 - Tzuriel Yamin

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接