ok, this seems to be the best:
system("command 2>/tmp/stderr.out 1>/tmp/stdout.out");

is there any recommended way how to directly read these files with
log4perl? I would like to append the output directly to output of
logger.

On Nov 22, 2007 12:54 AM, Kevin M. Goess <[EMAIL PROTECTED]> wrote:
> John Dunbar wrote:
> > Kevin, thank you for comprehensive reply.
> >
> >> Well, the safest and most direct way would be to replace/augment all the
> >> prints to STDERR (like "warn" and "die") inside your script with
> >> log4perl logger calls.
> >
> > I would prefer this solution, but how can I the redirect whole output
> > (or STDERR atleast) of the external command to die?
> > I am almost perl beginner, sorry, if this question is too easy.
>
> Sorry, I was assuming that this external command was perl code you had
> written.  If it's some other command you don't have access to, then you
> can either wrap it in perl and use temp files to capture the output
>
>    my $stdout = `command 2>/tmp/securetempfile`;
>
> or
>    system("command 2>/tmp/stderr.out 1>/tmp/stdout.out");
>
> (but use File::Temp to create the tempfile names, and keep in mind that
> the tempfiles can be accessed by anyone on that machine).
>
>
> >> Or you could pipe the output of your script to another script that reads
> >> STDIN and implements logging like this:
> >>
> >>  command 2>&1 | perl -e 'use Log::Log4perl qw/:easy/; \
> >>  Log::Log4perl::easy_init($INFO);  \
> >>  while (<STDIN>){INFO $_}'
> >
> > Can I do this in perl script directly?
> >
> >    use Log::Log4perl qw/:easy/;
> >    Log::Log4perl::easy_init($INFO);
> >    $pid = open(STDIN, "ls nonsense 2>/dev/null |");
> >    while (<STDIN>){INFO $_};
>
> See above with the backticks or the system call.
>
> > Is there any way how to redirect STDOUT to INFO and STDERR to ERROR?
> > If both is not possible, STDERROR to ERROR is more important.
>
> The tempfiles is a hacky but fairly reliable way to do it.  See also
> IPC::Open3, where you can get the stdout and stderr of your child
> process on differen handles.
>

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
log4perl-devel mailing list
log4perl-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/log4perl-devel

Reply via email to