pexpect output not getting generated

烈酒焚心 提交于 2019-12-14 03:12:59

问题


I’m having a problem with pexpect not providing any output of the commands that it runs. I’ve tried a variety of methods including installing we expect but there is no change in behavior. For example, when I do this:

#!/usr/bin/python                           
import sys, pexpect 
import os, subprocess, signal 

process = pexpect.spawn('/bin/bash')

process.sendline("export PS1=\"checkout-script:\"\r")
process.sendline("make\r") 
process.expect("checkout-script")
process.sendline("echo $?\r")
process.expect("checkout-script")
print process.before

print "Hello"

There is just a blank line indicating that process.before was blank. I then get Hello printed on the next line Even if I do this

#!/usr/bin/python                           
import sys, pexpect 
import os, subprocess, signal 

process = pexpect.spawn('/bin/bash')

process.sendline("export PS1=\"checkout-script:\"\r")
process.sendline("make\r") 
process.expect("checkout-script")
process.sendline("echo $?\r")
process.expect("checkout-script")
fout = file('mylog.txt','w')
process.sendline("export PS1=\"checkout-script:\"\r")
process.sendline("make\r") 
process.expect("checkout-script")
process.sendline("echo $?\r")
process.expect("checkout-script")
print process.before

print "Hello"

in order to put the input and the output in a text file, I only see the input. Please provide some insights on how I can troubleshoot this

来源:https://stackoverflow.com/questions/21219158/pexpect-output-not-getting-generated

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!