in reply to Re^2: 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

I don’t think so. You’re doing something else somewhere. And why the die? Might cloud order of ouput depending on what you do with the script.

moo@cow~>perl ab -help -m "double quote goes here" 'single quote goes +here' ab -help -m double quote goes here single quote goes here Died at ab line 3. __END__ This is perl 5, version 18, subversion 2 (v5.18.2) built for darwin-2l +evel

Replies are listed 'Best First'.
Re^4: Catch the exact command line including the quotation marks and so on
by CJmonk (Initiate) on Oct 23, 2015 at 21:02 UTC
    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!

      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…