Hey Jonathan, can this work in Win32 environment?

[color=Black]Yeah, I called you out on this one. :-)

I'm trying to redirrect STDERR to a file in a perl script on a Win32 server. But here's the kicker, I need to associate the line number in the script where the error occured...

I know hoe to redirrect STDERR:[/color]
[color=Blue][code]open(SAVE_STDERR, ">&STDERR") or die "Failed to save STDERR: $!";
open(STDERR, ">", "$logfile") or die "Failed to re-direct STDERR to '$logfile': $!";[/code][/color]

I also know of the method of capturing a commands STDERR, but I am not sure if this would work from within the script capturing STDERR's from processes called inside the script such as:
[code][color=Blue]$pid = open(PH, "[b]&run_this( $cmd )[/b] 2>&1 1>/dev/null |"); [/color][/code]

I know I need to some how be able to step through it kind of like the perl interpretor does when we 'use warnings' I guess..?

Could this be done from within the same script?
Any suggestions and/or ideas would be greatly appreciated...
Regards,
JoeMc

Comments

  • : I also know of the method of capturing a commands STDERR, but I am
    : not sure if this would work from within the script capturing
    : STDERR's from processes called inside the script such as:
    : [code]: [color=Blue]$pid = open(PH, "[b]&run_this( $cmd )[/b] 2>&1 1>/dev/null |"); [/color][/code]:
    :
    I very much doubt that this is portable and I don't think it will work on Win32. This module should provide a better and portable way:
    http://search.cpan.org/~nwclark/perl-5.8.8/lib/IPC/Open3.pm

    : I know I need to some how be able to step through it kind of like
    : the perl interpretor does when we 'use warnings' I guess..?
    Not quite sure what you mean by this. Though you mention wanting to get line number and so on, in which case see this module:
    http://search.cpan.org/~drolsky/Devel-StackTrace-1.15/lib/Devel/StackTrace.pm

    Note that to get what you want you may need to override the built-in die function, which I haven't ever done but believe to be possible.

    Jonathan
    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
  • : : I also know of the method of capturing a commands STDERR, but I am
    : : not sure if this would work from within the script capturing
    : : STDERR's from processes called inside the script such as:
    : : [code]: : [color=Blue]$pid = open(PH, "[b]&run_this( $cmd )[/b] 2>&1 1>/dev/null |"); [/color][/code]: :
    : :
    : I very much doubt that this is portable and I don't think it will
    : work on Win32. This module should provide a better and portable way:
    : http://search.cpan.org/~nwclark/perl-5.8.8/lib/IPC/Open3.pm
    :
    : : I know I need to some how be able to step through it kind of like
    : : the perl interpretor does when we 'use warnings' I guess..?
    : Not quite sure what you mean by this. Though you mention wanting to
    : get line number and so on, in which case see this module:
    : http://search.cpan.org/~drolsky/Devel-StackTrace-1.15/lib/Devel/Stack
    : Trace.pm
    :
    : Note that to get what you want you may need to override the built-in
    : die function, which I haven't ever done but believe to be possible.
    :
    : Jonathan
    : ###
    : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

    Much thanks Jonathan, I'll let you know how it turns out. :-)

    Regards,
    JoeMc

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion