【发布时间】:2018-07-18 07:34:33
【问题描述】:
我正在使用 python Fabric 中的运行命令远程执行脚本。
C = fabric.Connection('ip', user='user', connect_kwargs={"password": "password"})
try:
r = C.run('python3 ~/script.py')
if r:
print('{} SUCCESS'.format(C.host))
break
else:
print('{} ERROR'.format(C.host))
break
except:
print('{} ERROR'.format(C.host))
我的 script.py 是:
def download_file(url, filename):
try:
response = requests.get(url)
# Open file and write the content
with open(filename, 'wb') as file:
# A chunk of 128 bytes
for chunk in response:
file.write(chunk)
return 1
except requests.exceptions.RequestException as e:
return 0
download_file(url,filename)
当我执行运行命令时,有没有办法查看我的函数中返回的值是 1 还是 0?
谢谢!
【问题讨论】:
标签: python linux remote-access fabric