devslashneil has asked for the wisdom of the Perl Monks concerning the following question:

Hey Monks,

I am currently trying to open a process and send it some data, however the process (written in c) which i am trying to run, tests to make sure it is connected to a tty using the "isatty()" function.

Here is an example C program to describe what i mean.
#include <stdio.h> int main(int ac, char** av) { if (isatty(fileno(stdout))) printf("Is a tty!\n"); }
I was wondering if there is any way for me to run this program from within my perl script, while still proving that if statement true and then send the program data to it's stdin.

If i open the process using 'open()' then i am not attached to a valid tty, however if i run it using 'system()' i am unable to send data to it.

Once way i've thought of doing this is to run it using 'system()' then grep the tty of the pid, then open the tty and write to it, but this seems like a hack and i'm not sure if it will work?

Any help would be appreciated.

Neil Archibald

Replies are listed 'Best First'.
Re: Valid tty problem
by BUU (Prior) on May 05, 2004 at 03:15 UTC
    I think Expect should do what you want.
      Thankyou this was exactly right!

      When i run:
      #!/usr/bin/perl use Expect; my $exp = Expect->spawn('./test', undef) or die "Cannot spawn ./test.pl $!\n"; print $exp->expect;
      Against that C program it prints "Is a tty!".

      Thanks a lot for your help.

      Neil Archibald
Re: Valid tty problem
by chip (Curate) on May 05, 2004 at 03:52 UTC
    You're working way too hard. Just use the -t file test, as documented in "perlfunc".

        -- Chip Salzenberg, Free-Floating Agent of Chaos

      He's not trying to make his program know whether he was handed a tty. He's trying to hand something else a tty that his program controls.

      The filetest, therefore, doesn't help.

        "Oops."

            -- Chip Salzenberg, Free-Floating Agent of Chaos