Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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

by cdarke (Prior)
on Dec 03, 2007 at 10:26 UTC ( #654536=note: print w/replies, xml ) Need Help??


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

Depends what you mean. An example of the kind of 'command' you wish to test would help.
I am assuming you are running a child process using backticks or system. The problem with the return code $? with these is that they might invoke a shell, and it will be the return code from the shell you might pickup, not that of the shell command. Is it this that bothers you?
If so, your best bet is to execute the external program without invoking a shell. Avoid shell meta-characters like redirection, pipes, globbing, and so on. It is not that difficult to do all that from Perl before invoking the external program.
Alternatively execute the program using fork and exec (unless you are on Windows).
  • Comment on Re: Is it possible to determine last executed command line?

Replies are listed 'Best First'.
Re^2: Is it possible to determine last executed command line?
by bdimych (Monk) on Dec 03, 2007 at 10:53 UTC
    >Is it this that bothers you?

    No it is not. There are several places over my project where retcode_full_test() is called. So I just thought about minimize changes.

    After that, I'd thought, if global $? exists, why could not exist $"last_command_line"

    That's all, in general

      There is not much Perl can do about this. If you insist on invoking a shell then all that Perl can do is report what the shell returned. Anything further is outside its control.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (5)
As of 2023-11-29 18:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?