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

O monks greater than I,

Is there a standard utility that sends its STDIN to /dev/tty and sends /dev/tty to its STDOUT)?

To clarify my meaning; the following perl script does the job:

#!/usr/bin/perl use strict; if (my $pid = fork) { open TTY, "</dev/tty" or die $!; print while <TTY>; waitpid $pid, 0; } else { open TTY, ">/dev/tty" or die $!; select TTY; print while <>; }

I hope to find such a utility to give to the "command" parameter of IPC::Open2::open2, for debugging purposes.

Thanks,
 ~ Irrelevant

Replies are listed 'Best First'.
Re: dancing with /dev/tty (two pumps)
by tye (Sage) on Mar 07, 2007 at 21:28 UTC

      Ah, yes. That's exactly the sort of thing I was looking for. The "&-is-fork" idiom looks like it's well worth remembering for future bits-and-pieces, too.

      ++!

Re: dancing with /dev/tty
by Moron (Curate) on Mar 07, 2007 at 21:28 UTC
    Is there a reason why you can't just give the filename of the above script to the open2 in another script?

    -M

    Free your mind

      You make a good point, actually. Had no-one devised a solution, that's what i've'd ended up doing. I initially hoped to avoid re-inventing the wheel, but I did that anyway in the purpose of devising the description of what i meant. *g*

      As it is, I guess eliminating a script makes the code neater, and there won't come a time in the future when a maintainer sees this project (it having lasted unexpectedly long, as the quick hacks're wont to do) and thinks "WTF? This could be one line of shell script!". So at least I've saved face with the anonymous future, eh.

       ~ Irr