Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: Is it possible to determine last executed command line?

by bdimych (Monk)
on Dec 03, 2007 at 10:07 UTC ( [id://654535]=note: print w/replies, xml ) Need Help??


in reply to Re: Is it possible to determine last executed command line?
in thread Is it possible to determine last executed command line?

In brief

I have separate sub inside my project

sub retcode_full_test { # code taken from perldoc -f system if ($? == -1) { G::abend("failed to execute: $!"); } elsif ($? & 127) { G::abend(sprintf("child died with signal %d, %s coredump", ($? + & 127), ($? & 128) ? 'with' : 'without')); } else { return $? >> 8; } }
I've thought, that it would be better and it may be possible
sub retcode_full_test { # code taken from perldoc -f system if ($? == -1) { G::abend("failed to execute $?????: $!"); } elsif ($? & 127) { G::abend(sprintf("$????? died with signal %d, %s coredump", ($ +? & 127), ($? & 128) ? 'with' : 'without')); } else { return $? >> 8; } }

Replies are listed 'Best First'.
Re^3: Is it possible to determine last executed command line?
by apl (Monsignor) on Dec 03, 2007 at 10:55 UTC
    Rather than calling
    system( "....." ); retcode_full_text();
    you might consider modifying retcode_full_text to take the last command as an argument, and using

    my_system( "....." );

    with
    sub my_system { my ( $cmd ) = @_; system( $cmd ); retcode_full_text( $cmd ); }
      In case the caller wants to pass a list of command-line args to system(), you would want to do it like this (which seems simpler anyway):
      sub my_system { system( @_ ); retcode_full_text( "@_" ); }
        If you care about precision as opposed to readability, the following might be more appropriate.
        sub my_system { system( @_ ); retcode_full_text( join ' ', map quotemeta, @_ ); }

        At least for non-Windows systems.

      Or overriding the global system:
      BEGIN { *CORE::GLOBAL::system = \&my_system; }

      I'm not sure how to do this for backticks or pipe-open, though.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://654535]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-04-23 09:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found