Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re^3: Syncing perltie filehandle STDOUT STDERR and system call

by jandrew (Chaplain)
on Dec 17, 2012 at 15:49 UTC ( #1009189=note: print w/replies, xml ) Need Help??

in reply to Re^2: Syncing perltie filehandle STDOUT STDERR and system call
in thread Syncing perltie filehandle STDOUT STDERR and system call

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.

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

Replies are listed 'Best First'.
Re^4: Syncing perltie filehandle STDOUT STDERR and system call
by karthikm897 (Initiate) on Dec 22, 2012 at 15:50 UTC
    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

      karthikm897 I think you have an architecture problem. It appears that you are trying to splice perl into the middle of system interactions ('date' with no passed value) Whenever possible you are better off sticking to pure system calls or writing everything in perl. To choose the perl route, do some investigation around the functionality you are trying to implement not the call/response management of that functionality from the system. perl is amazingly powerful and you will probably not need a system call at all. (System calls in perl code are often categorized as "code smell")

      With that said if you still want to follow system capture as a tactic, check out this stackoverflow search.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2018-06-24 06:09 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.