Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在python中从另一个shell执行命令?_Python_Linux_Shell - Fatal编程技术网

如何在python中从另一个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

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

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)

我认为您正在寻找子流程