Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: Syncing perltie filehandle STDOUT STDERR and system call

by jandrew (Chaplain)
on Dec 14, 2012 at 16:02 UTC ( #1008863=note: print w/replies, xml ) Need Help??

in reply to Syncing perltie filehandle STDOUT STDERR and system call

I'm not sure I follow what you are trying to do in the big picture here so I have to ask if you have read the documentation for open. There is a section specifically dealing with redirecting STDOUT and STDERR. However, if after that review you still need some additional performance then you should investigate a really cool module from tobyink++ called IO::Callback that may fit your requirements.

Here is a Synopsis from him

  • Comment on Re: Syncing perltie filehandle STDOUT STDERR and system call

Replies are listed 'Best First'.
Re^2: Syncing perltie filehandle STDOUT STDERR and system call
by karthikm897 (Initiate) on Dec 17, 2012 at 09:14 UTC
    Thanks jandrew, I haven't tried with IO::Callback, with which I think I need not use tiefilehandle anyway. But yes for your question , I already tried using "open" in pipe mode, this is not going to help me with its syntax limitation as I have a different subroutine for stdout & stderr and I can't open a pipe for both at same time. though indiviual pipe did help me redirect to the tied module function call back.

      karthikm897 you are correct that you don't need to tie the file handle with IO::Callback. The trick there is to use the select command. On the other hand for STDERR there is a fair amount going on in the background with perl so I would reccomend either looking at the perl documentation for sigtrap or working with the special %SIG variable to target specific error message types rather than redirecting STDERR wholesale.

        Hi jandrew, I tried with IO::Callback, this din't work again. try this code
        use IO::Callback; # Here's the coderef my $code = sub { my $str = shift; print STDERR "This is really bad: $str"; }; # Turn it into a filehandle opened in write mode my $fh = IO::Callback->new('>', $code); # Select that filehandle (makes it the default for print, say, etc). select($fh); # Print something - it gets passed to the coderef! print "Hello World\n"; system("date");
        date output doesn't get default error meta text. Also this has been mentioned in Bugs section I already have a large number of pre-written scripts and trying to capture print STDERR from them, not the system generated error signals alone. So I would like to perform similar callback function for STDERR as well. Thanks

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1008863]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2018-01-17 11:47 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (198 votes). Check out past polls.