Professional Web Applications Themes

Pseudo Terminals and Stange Vi problem - UNIX Programming

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 ...

  1. #1

    Default Pseudo Terminals and Stange Vi problem

    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
    Peter Guest

  2. #2

    Default Re: Pseudo Terminals and Stange Vi problem

    In article <google.com>,
    Peter Tan <com> wrote: 

    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, 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.
    Barry Guest

  3. #3

    Default Re: Pseudo Terminals and Stange Vi problem

    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


    com (Peter Tan) wrote in message news:<google.com>... 
    Ecce Guest

  4. #4

    Default Re: Pseudo Terminals and Stange Vi problem

    > My question is what could have cause this behavior to happen? Do I 

    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.

    Michael Guest

Similar Threads

  1. PS7.0.1 very stange layer effects problem
    By iRudi@adobeforums.com in forum Adobe Photoshop Mac CS, CS2 & CS3
    Replies: 13
    Last Post: September 17th, 12:00 PM
  2. Stange error
    By ezd_macromedia in forum Macromedia Flex General Discussion
    Replies: 1
    Last Post: September 6th, 03:54 PM
  3. Gtk2: stange problem with notebook ?
    By oxman in forum Ruby
    Replies: 1
    Last Post: August 15th, 08:08 AM
  4. Packet mode pseudo terminals
    By Rich Teer in forum UNIX Programming
    Replies: 1
    Last Post: July 23rd, 12:13 AM
  5. pseudo tty stderr capture problem.
    By Min Shei in forum UNIX Programming
    Replies: 0
    Last Post: July 15th, 11:07 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139