【发布时间】:2018-09-10 07:38:05
【问题描述】:
我想在 python 中使用rlcone。 如果我不使用密码加密我的 rclone 配置,那么我可以简单地这样做:
import subprocess
process = subprocess.Popen(["rclone", "listremotes"], shell=True, stdin=subprocess.PIPE)
output = process.communicate()
print(output)
但我想用密码保护我的 Rclone 配置,所以我需要一种方法将其发送到 rclone。我关注了这个answer,但我收到了错误Failed to read password: The handle is invalid:
import subprocess
psw= input("enter psw")
psw_byte= str.encode(psw+'\n')
process = subprocess.Popen(["rclone", "listremotes"], shell=True, stdin=subprocess.PIPE,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
process.stdin.write(psw_byte)
process.stdin.flush()
output = process.communicate()
print(output)
【问题讨论】:
-
顺便说一句,
shell=True在这里是多余的。您既不需要也不想要 shell 来运行单个命令。 -
看来
rclone没有从标准输入中读取其密码。许多程序强制读取/dev/tty或类似的内容。运行脚本时可能有不同的方式来传递密码。 -
看文档,或许可以在调用子进程的时候用密码设置环境变量
RCLONE_CONFIG_PASS。
标签: python subprocess