python - 如何从python中的另一个shell执行命令?

标签 python linux shell

我想运行一些打开另一个 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/

相关文章:

python - 如何在多页面应用程序上使用plotly-dash下载文件?

c++ - 同样的代码在 Mac 上正确,在 Linux 上不正确

linux - 是否可以使用此系统检查登录失败,或者我需要使用expect?

bash - Shell 脚本在剪切后覆盖列

python - 新手需要 Python 教程的帮助

Python, Multiprocessing : what does process. join() 做什么?

linux - 用于测试入口流量的 Ping 命令

linux - 八进制数字0权限的用途是什么

windows - 如何从 Git Bash 中将命令行参数传递给 Windows 应用程序?

python - dbus-python 如何获得本地类型的响应?