in reply to Getting a script's original command line

in general, i don't think this is possible. there is no way to do it in Perl, i believe. however, under GNU/Linux, you can read from /proc/self/cmdline to get the command line of the current process.

the following worked for me under Linux 2.2:

open CMDLINE, "/proc/self/cmdline"; print map { $_, $/ } <CMDLINE>; close CMDLINE;
it still doesn't give you the exact command line though, just what was passed to exec. you would have to get the verbatim command line from the shell, and at least under BASH, it is not in %ENV.

update: Randal correctly noted that the arguments from /proc/self/cmdline are NUL-separated, so the following works better:

$/ = "\x000"; $\ = "\n"; open CMDLINE, "/proc/self/cmdline"; print for (<CMDLINE>); close CMDLINE;

Replies are listed 'Best First'.
RE: Re: Getting a script's original command line
by merlyn (Sage) on Jun 16, 2000 at 20:40 UTC
RE: Re: Getting a script's original command line
by blackwolf (Sexton) on Jun 16, 2000 at 20:57 UTC
    This is getting a little too nasty to implement portably, similar to the solutions I'd come up with. Portability is an issue, so the /proc/self/cmdline option's out.

    I think the best solution is Randal's "strategy rethink". What else did I have to do today, anyway? :)