执行以下脚本时(简化示例):
#!/usr/bin/env python
import pexpect
spawn = pexpect.spawn('/bin/bash')
with open('/tmp/logfile.log', 'w') as f:
spawn.logfile_read = f
spawn.sendline('echo "Hello I am a really long command, in fact I am 100 characters long! Potato Potato Potato....."')
spawn.sendline('exit')
spawn.expect(pexpect.EOF)
我在换行时遇到问题,导致^M
日志中出现字符。pexpect 日志文件现在看起来像这样:
bash-3.2$ echo "Hello I am a really long command, in fact I am 100 characters lo ^Mng! Potato Potato Potato....."
Hello I am a really long command, in fact I am 100 characters long! Potato Potato Potato.....
bash-3.2$ exit
exit
在 80 个字符之后,该行被回车换行,我不希望这样。我尝试了很多不同的方法来禁用换行(使用,预先tput rmam
调用,使用,设置,将各种参数传递给 /bin/bash..),但我似乎找不到正确的技巧。stty columns 1000
spawn.setwinsize(1000, 1000)
os.environ['COLUMNS'] = "1000"
在这种情况下如何禁用换行?