unbuffer script using pexpect

K

Krutibas Biswal

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top