windows子进程上的Python don´;行不通

windows子进程上的Python don´;行不通,python,subprocess,password-protection,unrar,Python,Subprocess,Password Protection,Unrar,我想测试打开一个winrar密码保护的文件,测试单词的发音。 这是我的代码,但它不工作,能帮我什么忙吗?谢谢 import subprocess def extractFile(rFile, password): try: subprocess.call(['c:\\mio\\unrar\\unrar.exe -p'+password+'x C:\\mio\\unrar\\'+rFile,'shell=True']) return password except: ret

我想测试打开一个winrar密码保护的文件,测试单词的发音。 这是我的代码,但它不工作,能帮我什么忙吗?谢谢

import subprocess
def extractFile(rFile, password):
try:
    subprocess.call(['c:\\mio\\unrar\\unrar.exe -p'+password+'x C:\\mio\\unrar\\'+rFile,'shell=True'])
    return password
except:
    return
def main():    
rFile = "c:\\mio\\unrar\msploit.rar"
passFile = open("C:\\mio\\unrar\\dic.txt")
for line in passFile.readlines():
    password = line.strip('\n')

    guess = extractFile(rFile, password)
    print(password)
    if guess:
       print '[+] Password = ' + password + '\n'
       break
if __name__ == '__main__':
main()

call()
的第一个参数是数组,但使用full命令。尝试以下方法:

subprocess.call(['unrar.exe', 'x', '-p'+password, rarfn], shell=True)
编辑:

我认为您还必须检查是否创建了输出文件。密码不正确的
unrr
可能无法创建输出文件。检查它是否已创建(例如使用
os.path.isfile()
)。您还可以检查
unrr
输出以查看问题所在

EDIT2:

似乎没有x
rar
命令来提取具有完整路径的文件

这是一个工作示例,我使用密码文件
Order.htm
进入
Order.rar
,然后删除了
Order.htm

rarfn = 'Order.rar'
outfn = 'Order.htm'
if os.path.isfile(outfn):
    print('%s already exists!!!' % (outfn))
else:
    for password in ('ala', 'ma', 'kota', 'zorro', 'rudy'):
        print('testing %s...' % (password))
        subprocess.call(['unrar.exe', 'x', '-p'+password, rarfn], shell=True)
        if os.path.isfile(outfn):
            print('guessed: [%s]' % (password))
            break

您必须缩进
main()
行(最后一行)您能解释一下
不起作用是什么意思吗?当询问您的代码有问题时,请更加具体。@CharlesB和其他行。您希望通过将
,'shell=True'
放入数组而不是将其作为函数的参数来实现什么?在我的回答中,您将看到
call()
有错误的参数,但我认为,即使
call()
成功,您也可能猜不到正确的密码,然后
unrr
可能会显示一些错误,并且不会创建输出文件。谢谢,在dos模式下,unrr与unrr-ppassword xfile.rar一起工作正常,但在subprocess调用中,这是:subprocess.call(['c:\\mio\\unrr\\unrr.exe','-p',密码,'xC:\\mio\\unrr\',rFile])打开dos窗口,但手动等待密码