返回非零退出状态123

时间:2013-12-06 08:32:06

标签: python

我正在编写一些代码,假设从文件夹中获取权限列表,并将此列表中的users \ group列表与另一个列表进行比较,如果它们之间存在合适,则将文件夹路径写入文件。 这是代码:

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()     在check_output中的文件“C:\ Python33 \ lib \ subprocess.py”,第586行     引发CalledProcessError(retcode,process.args,output = output)     subprocess.CalledProcessError:命令'['cacls',“['D:\\ Scripting \\ permissi     on project'“]'返回非零退出状态123

任何想法?

1 个答案:

答案 0 :(得分:0)

该消息说该命令返回退出状态123,表示错误。

根据http://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx,状态123表示

  

文件名,目录名或卷标语法不正确。

您的目录名可能有问题?似乎有太多的空间。