如何在python中从另一个shell执行命令?
我想运行一些命令来打开另一个shell,在那里我可以键入特定的命令。在这个shell中,我想在循环中运行另一个命令。 更具体地说,在我的示例中,它如下所示:如何在python中从另一个shell执行命令?,python,linux,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 re
> 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
connect = 'openssl s_client -connect 10.10.10.10:10000'
subprocess.call(connect.split(), shell=False)
while (something):
subprocess.call('R', shell=False)
最好的方法是什么?提前感谢您对子流程的任何帮助,如下图所示
import subprocess
cmd = 'ls -la'
subprocess.call(cmd.split(), shell=False)
因此,在您的情况下,应该是这样的:
> 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
connect = 'openssl s_client -connect 10.10.10.10:10000'
subprocess.call(connect.split(), shell=False)
while (something):
subprocess.call('R', shell=False)
我认为您正在寻找子流程