【发布时间】:2019-01-06 05:32:02
【问题描述】:
这是我的代码:
import subprocess
def megaGetFile(fileLink,downloadFolder):
bashCommand = "mega-get --ignore-quota-warn " + fileLink + " " + downloadFolder
output = subprocess.check_output(['bash','-c', bashCommand])
print(output)
inecekLink="https://mega.nz/#!KG4FTKjA!ZF5gOE4HPnvo1Ua3kFg5QK5EvZi15enQ4yCRMs2REtA"
nereye="/home/pi/Desktop/"
inecek="https://mega.nz/#!PC4xRSqA!vYHRQ1RYEagVWAgtQsGK8QRI3AqS_BjfV2ZV-GP9Vgw"
megaGetFile(inecekLink,nereye)
inecekLink 正在下载但返回代码:b' ' inecek 没有下载,因为我删除了它并返回代码:
Traceback (most recent call last):
File "./megaCMD.py", line 50, in <module>
megaGetFile(inecek,nereye)
File "./megaCMD.py", line 36, in megaGetFile
output = subprocess.check_output(['bash','-c', bashCommand])
File "/usr/lib/python3.5/subprocess.py", line 316, in check_output
**kwargs).stdout
File "/usr/lib/python3.5/subprocess.py", line 398, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['bash', '-c', 'mega-get --ignore-quota-warn https://mega.nz/#!PC4xRSqA!vYHRQ1RYEagVWAgtQsGK8QRI3AqS_BjfV2ZV-GP9Vgw /home/pi/Desktop/']' returned non-zero exit status 247
如何获取成功和错误代码?
【问题讨论】:
-
the documentation for subprocess.check_output() 中的错误处理行为非常明确,我会去那里看看。
标签: python python-3.x error-handling subprocess