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

Greetings, esteemed monks!

: How to use a psuedoterminal for both STDERR && STDOUT while doing something slightly different w/each?

I'll admit I posted a similar node but it degraded into a discussion of whether my code was readable and not the issue at hand. I'm looking for a fresh start so here goes. (I've also run the code through perltidy :) )

I'd like to use a pty to trick the called program (usually another perl script) into thinking it's interacting with a tty on both STDERR and STDOUT to get the output as synchronously as possible (but I know it'll never be perfect).

I'll just post the one relevant line here, and before you ask, yes I'm using strict! LOL

What I'm doing now is

run( \@cmd, '>pty>', sub { print "$_[0]"; }, '2>', sub { chomp $_[0]; print "<b><em>$_[0]</em></b>\n"; } ) or warn("Error executing child. Child returned $?\n");
, which is pretty close to being synchronous processing of STDERR & STDOUT, comparatively speaking. I thought I could get them closer by doing
run( \@cmd, '>pty>', sub { print "$_[0]"; }, '2>pty>', sub { chomp $_[0]; print "<b><em>$_[0]</em></b>\n"; +} ) or warn("Error executing child. Child returned $?\n");
but, alas, '>pty>' really means '&>pty>'. So nothing ever makes it to my STDERR processor. Is there a way to have two separate ptys? Put '2>pty>' first?

TIA, Terrence

_________________________________________________________________________________

I like computer programming because it's like Legos for the mind.

Replies are listed 'Best First'.
Re: IPC::Run woes
by OfficeLinebacker (Chaplain) on Jun 07, 2006 at 15:02 UTC
    Greetings, esteemed monks!

    So I tried

    run( \@cmd, '2>pty>', sub { chomp $_[0]; print "<b><em>$_[0]</em></b>\n"; +}, '>pty>', sub { print "$_[0]"; } ) or warn("Error executing child. Child returned $?\n");
    and THAT just sends everything to the STDERR processor. I'll look into the PTY module I guess. In any case, from looking at the output, it doesn't help with sychronicity. (Which was a great album, BTW)

    Cheers,

    Terrence

    _________________________________________________________________________________

    I like computer programming because it's like Legos for the mind.