Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Syncing perltie filehandle STDOUT STDERR and system call

by karthikm897 (Initiate)
on Dec 14, 2012 at 12:09 UTC ( #1008822=perlquestion: print w/ replies, xml ) Need Help??
karthikm897 has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I wrote script1.pl which ties STDOUT and STDERR with modifyout.pm and modifyerr.pm respectively. tied print function in modifyout.pm will look like

sub PRINT { my $class = shift; #orig_stdout is file pointer to /dev/stdout return print orig_stdout *some_stdout_wrapper_text* @_; }

All print statements from script1.pl gets this wrapper automatically. But when there is a system command, the output of it doesn't get a wrapper. I tried using other alternatives like  IPC::Run3, Capture::Tiny with these I am not getting my requirements fulfilled that XS's(through system command in this case) stdout should be passed through modifyout.pm and stderr through modifyerr.pm and they all should be buffered immediately.

Could someone please help me on this ?

Comment on Syncing perltie filehandle STDOUT STDERR and system call
Select or Download Code
Re: Syncing perltie filehandle STDOUT STDERR and system call
by Anonymous Monk on Dec 14, 2012 at 12:19 UTC
Re: Syncing perltie filehandle STDOUT STDERR and system call
by jandrew (Hermit) on Dec 14, 2012 at 16:02 UTC

    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

      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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1008822]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2014-09-24 03:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (245 votes), past polls