How to cheat a program expecting a terminal

How to cheat a program expecting a terminal

Post by Konstantin Shemya » Sat, 21 Jul 2001 20:34:03



On my Unix (HP-UX 11), I found out that a command I need to use
("netstat -i -I <interface> <time_interval>") refuses to output
anything in case when the stdout is not a terminal. (Quite stupid
IMHO; other combinations of options work OK!) So, whenever I
redirect or pipeline to anything which is not, nothing is printed.
I wish I knew how the check is done; eg. if I create a symlink
to /dev/tty and redirect to print to that symlink, the output
is going normally...

Is there a way to "cheat" the program and make it believe that
stdout (file descriptor 1) is a terminal, while it is connected
to a plain file?

Konstantin Shemyak

 
 
 

How to cheat a program expecting a terminal

Post by Stephane Chazel » Sun, 22 Jul 2001 00:04:58



> On my Unix (HP-UX 11),
[...]
> Is there a way to "cheat" the program and make it believe that
> stdout (file descriptor 1) is a terminal, while it is connected
> to a plain file?

I don't know if it will work under HP-UX, but you could try something
like:

cat > /tmp/script.sh << EOF
#! /bin/sh
the_command that expects a terminal env
EOF
chmod u+x /tmp/script.sh
SHELL=/tmp/script.sh script /dev/fd/3 3> plain_file > /dev/null

You may want to remove header and footer lines added by the "script"
command.

--
Stphane

 
 
 

How to cheat a program expecting a terminal

Post by Bill Marcu » Sun, 22 Jul 2001 04:42:21



>Is there a way to "cheat" the program and make it believe that
>stdout (file descriptor 1) is a terminal, while it is connected
>to a plain file?

man expect
 
 
 

How to cheat a program expecting a terminal

Post by Heiner Steve » Sun, 22 Jul 2001 06:55:05



 > >
 > >Is there a way to "cheat" the program and make it believe that
 > >stdout (file descriptor 1) is a terminal, while it is connected
 > >to a plain file?
 > >
 > man expect

The book

    Stevens, Richard W.: Advanced Programming in the UNIX Environment.
        Addison-Wesley, Reading 1992

contains the source code for a program called "pty", which does
exactly what you want. You could use it in the following way:

        pty passwd < password

I remember having some problems porting it to non-SVR4 UNIX systems,
however...

Heiner
--
 ___ _

\__ \  _/ -_) V / -_) ' \    Shell Script Programmers: visit
|___/\__\___|\_/\___|_||_|   http://www.shelldorado.com/

 
 
 

1. need recommendation for good TCP\IP program and Terminal Program for FREEBSD 2.2.6

I have linux 2.2.6 installed on 400 meg partition with xwindows running
well. I also have netscape 4.x running well. I have 686 200 with Plug and
play bios and plug and play modem and sound card. Can anyone recommed a good
terminal program and PPP dialer program to install. especially easy would be
if they are allready on the 4 CD FreeBSD set.

Thanks

2. NT Loader or LILO?

3. expect - process id in the remote terminal

4. ZIP drives - again...

5. Expect: expect vs. interact

6. Cx486 cache helps, just one question

7. Expect/Tcl Problem - "scripts expect Tcl version..."

8. Enterprise-Wide LP Support (sigh...)

9. expect and expecting it this way or this way...?

10. How to compile EXPECT was WANTED expect for Linux

11. expect for AIX where can I find freeware.expect.rte

12. expect-send pairs and sub expect-send pairs in chat

13. Expect: How to expect clear screen