执行unix命令的子进程

2024-06-03 14:16:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我基本上想连接到我的模拟器从那里执行几个命令。 在unixshell中,我通过发出命令“gmake CONFD\u NUMBER=1nthconfdcli”从unixshell连接到模拟器,但是当我运行下面的脚本时,我的代码挂起。你知道吗

def Simulator():
    command = "gmake CONFD_NUMBER=50 nthconfdcli"
    p = subprocess.Popen(command,shell=True,stdout=subprocess.PIPE)
    (output, err) = p.communicate()
    p.expect("#")
    p.sendline('show test cli');
    p.expect (['#',pexpect.EOF])
    show = p.before      
    print show

    p.sendline('exit');

Tags: 代码命令脚本numberdefshow模拟器command