in reply to Catch the exact command line including the quotation marks and so on

What's wrong with saving @ARGV at the start of your program? You won't get the parameters given to perl itself, but that shouldn't bother you IMO.

Replies are listed 'Best First'.
Re^2: Catch the exact command line including the quotation marks and so on
by ww (Archbishop) on Oct 23, 2015 at 11:59 UTC

    I probably missed something, but the output in the following still drops the input (CLI) double-quotes under Win7:

    my @input = @ARGV; say @input = join(" ", @input); =head CLI and output, AS perl 5.18.4, Win 7: C:\>@argv_test.pl foo bar baz 'bat' "bitchin" foo bar baz 'bat' bitchin ^ ^ =cut

      Ah - yes, I would blindly quote everything from @ARGV, sorry.

Re^2: Catch the exact command line including the quotation marks and so on
by CJmonk (Initiate) on Oct 23, 2015 at 20:00 UTC
    Hi, I don't get the desired behavior with ARGV. Here is an example:

    perl CJ.pl -help -m "double quote goes here" 'single quote goes here'

    if I do

    my $script = join " ", $0, @ARGV; print "$script \n "; die;

    I get:

    CJ.pl -help -m doublequotegoeshere singlequotegoeshere

    As you can see, not only quotes are gone, the spaces in the message is removed too! Here is the perl info I am using on Mac:

    This is perl 5, version 16, subversion 3 (v5.16.3) built for darwin-th +read-multi-2level

      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
        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!