in reply to Re: quoting issue with system command
in thread quoting issue with system command

Unfortunately, that doesn't work on Win32. Of course, I believe we should just fix that (though a bit of mushiness on how such things need to be quoted means that the fix wouldn't be foolproof, but I think it is clearly something Perl should try to do). To be specific, system(@list) on Win32 Perl is just the same as system("@list"), unfortunately.

- tye        

Replies are listed 'Best First'.
Re^3: quoting issue with system command (Win32)
by ikegami (Patriarch) on May 13, 2009 at 00:40 UTC
    It works for me.
    my $hu_seq = 'value of $hu_seq'; my $hd_seq = 'value of $hd_seq'; my $contig = 'value of $contig'; my $alignment = 'value of $alignment'; my @command = ( 'echo', '-leprint for @ARGV', '--', '-p', 'blastn', '-d', "$hu_seq $hd_seq", '-i', $contig, '-o', $alignment ); 0 == system @command or die "system @command failed: $?";
    >c:\progs\perl5100\bin\perl t.pl "-leprint for @ARGV" -- -p blastn -d "value of $hu_seq value of $hd_se +q" -i "value of $contig" -o "value of $alignment" >c:\progs\perl589\bin\perl t.pl "-leprint for @ARGV" -- -p blastn -d "value of $hu_seq value of $hd_se +q" -i "value of $contig" -o "value of $alignment" >c:\progs\perl580\bin\perl t.pl "-leprint for @ARGV" -- -p blastn -d "value of $hu_seq value of $hd_se +q" -i "value of $contig" -o "value of $alignment" >c:\progs\perl561\bin\perl t.pl "-leprint for @ARGV" -- -p blastn -d "value of $hu_seq value of $hd_se +q" -i "value of $contig" -o "value of $alignment"

    Here's a version where what you said is true:

    >c:\progs\perl560\bin\perl t.pl -leprint for @ARGV -- -p blastn -d value of $hu_seq value of $hd_seq - +i value of $contig -o value of $alignment

    (Switch echo for $^X for another view.)

    These are all ActivePerl builds.

      Thanks. It is nice that this got done. perl58delta says:

      The behavior of system() with multiple arguments has been rationalized. Each unquoted argument will be automatically quoted to protect whitespace, and any existing whitespace in the arguments will be preserved. This improves the portability of system(@args) by avoiding the need for Windows C<cmd> shell specific quoting in perl programs.

      Note that this change only applies to Win32.

      - tye        

        I guess what I learned about it is out of date, too.

        His example used "echo", which is something I expect of CMD.exe, not something that works with CreateProcess.

        I looked at the source, and can't make heads nor tails of it. I can't find the ActiveState source on their site anymore, so I looked at the generic perl source.

        So, does it always run the shell? I thought the list form would bypass it. I think it's high time that we update the docs with what really happens.

        —John

      Interestingly, when I run your snippet with an ActivePerl 5.8.8, I get the undesirable behavior (no quoting) you report with 5.6.0:

      c:\>perl t.pl -leprint for @ARGV -- -p blastn -d value of $hu_seq value of $hd_seq - +i value of $contig -o value of $alignment

      So there seems to be more to it than just version > 5.6.0 (?)

      In order to keep, lets say, 'value of $alignment' together as one argument, I have to define an ugly my $alignment = '\"value of $alignment\"';.

      c:\>perl -v This is perl, v5.8.8 built for MSWin32-x86-multi-thread (with 25 registered patches, see perl -V for more detail) Copyright 1987-2006, Larry Wall Binary build 817 [257965] provided by ActiveState http://www.ActiveSta +te.com Built Mar 20 2006 17:54:25
        That makes no sense. I have that exact build, and I get quotes:
        >c:\progs\perl588_817\bin\perl t.pl "-leprint for @ARGV" -- -p blastn -d "value of $hu_seq value of $hd_se +q" -i "value of $contig" -o "value of $alignment" >c:\progs\perl588_817\bin\perl -v This is perl, v5.8.8 built for MSWin32-x86-multi-thread (with 25 registered patches, see perl -V for more detail) Copyright 1987-2006, Larry Wall Binary build 817 [257965] provided by ActiveState http://www.ActiveSta +te.com Built Mar 20 2006 17:54:25 Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 5 source ki +t. Complete documentation for Perl, including FAQ lists, should be found +on this system using "man perl" or "perldoc perl". If you have access to + the Internet, point your browser at http://www.perl.org/, the Perl Home Pa +ge.

        Maybe your echo is different. (Got cygwin?) Try switching echo for $^X:

        >c:\progs\perl588_817\bin\perl t.pl -p blastn -d value of $hu_seq value of $hd_seq -i value of $contig -o value of $alignment

        Perhaps you have an echo.exe in your %PATH% such that Perl's system("echo ...") runs echo.exe instead of asking cmd.exe to use its internal echo command. For example, if you have cygwin installed, you'd get cygwin's echo.exe which will interpret the quotes and not output them instead of cmd.exe's echo command which includes the quotes in the output:

        C:\>\Apps\cygwin\bin\echo.exe "foo" foo C:\>echo "foo" "foo"

        Unfortunately, this is a new laptop and I only have cygwin Perl installed at the moment so I can't demonstrate the situation more directly (since cygwin Perl uses /bin/sh for system not cmd.exe).

        Change the test script to use 'cmd', '/c', 'echo' instead of just 'echo' ? Or change %PATH% or rename echo.exe temporarily.

        - tye