in reply to quoting issue with system command

Use a list instead of a string:

my @command = ( 'c:\\blast\bin\blastall', '-p', 'blastn', '-d', "$hu_s +eq $hd_seq", '-i', $contig, '-o', $alignment ); print "@command\n"; 0 == system @command or die "system @command failed: $?";

Replies are listed 'Best First'.
Re^2: quoting issue with system command (Win32)
by tye (Sage) on May 13, 2009 at 00:02 UTC

    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        

      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        

        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