【问题标题】:returned non-zero exit status 123返回非零退出状态 123
【发布时间】: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


【解决方案1】:

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

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

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

也许你的目录名有问题?空间似乎太大了。

【讨论】:

  • 当我尝试在某个文件夹的另一个脚本中单独运行 per_check 时,它工作正常。但是当我在这个脚本中给她打电话时,我收到了这条消息
  • 您检查发送到check_per 的路径是否正确?也许它会以某种方式被破坏?
  • tnx,这是我应该在发送到函数之前清理一些残留物的问题
猜你喜欢
  • 2017-05-18
  • 2022-11-01
  • 2014-01-13
  • 2016-08-09
  • 2019-10-02
  • 2019-02-06
  • 2014-07-26
  • 1970-01-01
  • 2017-05-20
相关资源
最近更新 更多