问题
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