python - python子进程和wget询问密码
问题描述
我正在运行以下 python 代码:
import subprocess
host = "ftp://localhost:2121"
p = subprocess.Popen(
['wget', '-P', '/tmp/output', '-N', '-r', '-l', 'inf', '--ask-password', '--user', 'anonymous', host],
stdin=subprocess.PIPE)
p.communicate("password\n")
if p.returncode != 0:
raise RuntimeError('wget command failed with return code: %d' % p.returncode)
似乎password
没有发送到 wget,因为脚本将挂起显示:
Password for user ‘anonymous’:
按下回车键会导致 wget 退出并返回错误代码“1”
按下键然后按下回车键会导致 wget 按预期开始下载。
ftp 服务器是本地的并且启用了匿名访问。Python 版本为 2.7.8
解决方案
推荐阅读
- sql-server - SQL Server - 从多种格式的字符串中提取日期
- r - 如何在测试数据集上获得随机森林回归模型的 MSE
- winapi - 当通过鼠标单击或以编程方式设置焦点时,列表框不会显示键盘插入符号
- javascript - 如何从initautocomplete表单获取值到initmap
- laravel - 空白页 laravel
- ios - 在 Swift 中使用自定义分段控件时 CollectionCell 数据显示问题
- ios - 通知服务扩展可以使用通知而不向用户显示吗?
- nginx - 通过 nginx 暴露的 s3fs 卷
- c# - 步幅的另一个问题
- json - 我正在尝试将我的 JSON 显示到我的 UIImageView 和 UILabel