Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Pseudo Terminals and Stange Vi problem

3 views
Skip to first unread message

Peter Tan

unread,
Sep 9, 2003, 2:48:39 PM9/9/03
to
Hello,
In the process of capture STDIN, STDOUT, and STDERR from the unix
shell, I have written a C program that creates 3 pseudo terminals.
Each of these pseudo terminals is connected to STDIN, STDERR, STDOUT
of the child process that runs
the unix shell program. So far every thing work just fine in the
shell, including telnet, ftp, passwd commands.
However when I start running vi editor, it seems that all key
binding in vi stops working, e.g. when I press arrow key, only garbage
shows up. I can't scroll up and down the editor. Also even if I am not
in the insertion mode, the command buttons like j, k, x etc. does not
work and this lettter shows up on screen intead. I tried to set the
environment variable TERM to value vt100
but that does not solve the problem.
Two other commands which are "more" and "man" do not work as well.
When I press space key or return key the screen suppposes to scroll up
and display more content, but inmy case nothing happen.
My question is what could have cause this behavior to happen? Do I
have to
set my terminal characteristics to be certain values? Note that my
program is a modified version of script program.

Thank you for your help,
-Peter

Barry Margolin

unread,
Sep 9, 2003, 2:55:16 PM9/9/03
to
In article <151c6c1d.03090...@posting.google.com>,

Full-screen programs like these often make use of /dev/tty rather than
stdin, stdout, and stderr. In particular, consider:

someprogram | more

more's stdin is the pipe, so it uses /dev/tty to perform user interaction.

It sounds like your program is not setting up the controlling terminal
properly.

--
Barry Margolin, barry.m...@level3.com
Level(3), Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

Ecce Nihil

unread,
Sep 11, 2003, 4:35:11 AM9/11/03
to
It might be that you have not set up the terminal characteristics for
these sort of interactive programs. vi etc require non-canonical mode
and min=1, and turn the echo off. Try...
tcsetattr(STDIN_FILENO,TCSANOW,&ti);
ti.c_lflag&=~ECHO;
ti.c_lflag&=~ICANON;
ti.c_cc[VMIN]=1;
tcsetattr(STDIN_FILENO,TCSANOW,&ti);

see the termio man page


shiu...@yahoo.com (Peter Tan) wrote in message news:<151c6c1d.03090...@posting.google.com>...

Michael Pradel

unread,
Sep 11, 2003, 11:58:32 AM9/11/03
to
> My question is what could have cause this behavior to happen? Do I
> have to
> set my terminal characteristics to be certain values? Note that my
> program is a modified version of script program.

I was working on a similar problem and this source code:
http://people.redhat.com/johnsonm/lad/src/ptytest.c.html
helped me a lot.
Especially this part should help you:

tcgetattr(STDIN_FILENO, &ot);
t = ot;
t.c_lflag &= ~(ICANON | ISIG | ECHO | ECHOCTL | ECHOE | \
ECHOK | ECHOKE | ECHONL | ECHOPRT );
t.c_iflag |= IGNBRK;
t.c_cc[VMIN] = 1;
t.c_cc[VTIME] = 0;
tcsetattr(STDIN_FILENO, TCSANOW, &t);

Michael.

0 new messages