我想运行一些打开另一个 shell 的命令,我可以在其中键入特定命令。在那个 shell 中,我想循环运行另一个命令。 更具体地说——在我的例子中它看起来像这样:
> openssl s_client -connect 10.10.10.10:10000 ### this is the first command
CONNECTED(00000003) ### some output
(...)
### now i'd like to type 'R' in a loop (R means renegotiate)
最好的方法是什么?在此先感谢您的帮助
最佳答案
有了子流程,就像这样。
import subprocess
cmd = 'ls -la'
subprocess.call(cmd.split(), shell=False)
所以在你的情况下它会是这样的:
import subprocess
connect = 'openssl s_client -connect 10.10.10.10:10000'
subprocess.call(connect.split(), shell=False)
while (something):
subprocess.call('R', shell=False)
关于python - 如何从python中的另一个shell执行命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45189472/