unbuffer script using pexpect

Krutibas Biswal kbiswal at gmail.com
Thu Jul 14 14:02:34 EDT 2005


Hi,
 I am using a script 'unbuffer' for unbuffering my outputs when using
pipes.
This script is based on expect and looks like this :
----------------------------------------------
#!/usr/bin/expect --
# Description: unbuffer stdout of a program
# Author: Don Libes, NIST

eval spawn -noecho $argv
set timeout -1
expect
----------------------------------------------

Now if you do

% unbuffer <commands with pipes>
it works fine.

I am trying to write a similar similar script in python (pexpect) and
it
looks like this :

------------------------------------------------------------
#!/usr/bin/env python
# Description: unbuffer stdout of a program and return program's error
code

import pexpect
import sys

child = pexpect.spawn(' '.join(sys.argv[1:]))
child.expect('(.+\n)+')
sys.stdout.flush()
child.interact() # Escape character defaults to ^]

sys.exit(child.exitstatus)
------------------------------------------------------------

This script works fine except that after the output is displayed
on the screen, it expects me to press <enter> to comeback to the
prompt. What is wrong here ? (I am a newbie)

Thanks,
Krutibas




More information about the Python-list mailing list