in reply to Re^3: Catch the exact command line including the quotation marks and so on
in thread Catch the exact command line including the quotation marks and so on

You are right. I was using Getopt::Declare without defer{}, and that was the result. die is there since I am testing, and I don't want the whole process to run. nothing to worry about!

OK. I ended up doing the following. It is not exact but it helps me build meaningful command (based on recommendations on http://stackoverflow.com/questions/6156742/how-can-i-capture-the-complete-commandline-in-perl). Double quote and single quote are just replaced by double quote.

my $cmd = `ps -o args $$ | grep CJ.pl`; my @cmd = split(/\s/,$cmd); my $cmdline = "$cmd[0] "." $cmd[1]"; foreach (@ARGV) { $cmdline .= /\s/ ? " \"" . $_ . "\"": " " . $_; } print "$cmdline\n";

But I still think perl should have a better way of catching the command line. It is bizarre that you can't simply get it exact!

Replies are listed 'Best First'.
Re^5: Catch the exact command line including the quotation marks and so on
by soonix (Chancellor) on Oct 24, 2015 at 17:49 UTC

    Perl is called by the shell. The shell does preprocess the arguments (as you already observed), and hands only the already preprocessed arguments over to Perl, so Perl has no chance.

    You might try reading from ~/.bash_history, but that won't work with other shells…