python - 从需要用户输入的python运行linux命令
问题描述
我有以下python代码:
import subprocess
p=subprocess.Popen(["openssl","genrsa","-aes256","-out","ise.key.pem","2048"],stdin=subprocess.PIPE,stdout=subprocess.PIPE)
inputdata="123456"
p.communicate(input=inputata)
p.communicate(input=inputata)
上面代码的输出是:
pan@pan:~/python-scripts$ Generating RSA private key, 2048 bit long modulus
........................+++
...................................+++
e is 65537 (0x10001)
Enter pass phrase for ise.key.pem:
User interface error
140617148802712:error:0906906F:PEM routines:PEM_ASN1_write_bio:read key:pem_lib.c:379:
我希望输入应该由 python 提供,不应该有任何用户交互:
我知道证书可以由 python pyOpenSSL 库生成,但我想使用普通的 linux 命令
我的python版本是:
Python 2.7.12 (default, Dec 4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "enter code here`license" for more information.
我看到了以下链接,但没有帮助
如果您在 shell 中运行该命令,它将运行如下:
pan@pan:~/python-scripts$ openssl genrsa -aes256 -out ise.key.pem 2048
Generating RSA private key, 2048 bit long modulus
..............................................................+++
..+++
e is 65537 (0x10001)
Enter pass phrase for ise.key.pem:
Verifying - Enter pass phrase for ise.key.pem:
解决方案
推荐阅读
- java - Java 8 中 java.time 包中的时间戳和 Timespan 等效项
- dart - 错误:找不到吸气剂:'defaultType'。渡槽,飞镖,vscode
- javascript - 如何在 URL 中传递变量值?
- c++ - 创建一个结构数组
- android - Android:如何在同一用户的设备之间同步存储在 Room 数据库中的应用程序数据?
- javascript - 使用 SortableJS 访问拖动的元素和替换的元素的 data-id
- docker - DockerHub 中的 Jenkins 使用哪个图像?是否列出了多种类型的图像?
- java - 最优检查并从 hashmap 中获取值
- javascript - 如何避免嵌套数组中维度之间的交叉引用?
- chaiscript - 将类的非静态成员函数暴露给 chaiscript