in reply to Re^3: quoting issue with system command (Win32)
in thread quoting issue with system command

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

Replies are listed 'Best First'.
Re^5: quoting issue with system command (Win32)
by ikegami (Patriarch) on May 13, 2009 at 02:02 UTC
    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
      Maybe your echo is different.

      Ah, right, that seems to be the issue — apparently, my echo is swallowing the quotes...  With $^X, perl is being passed the arguments as expected:

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

      So far so good.  OTOH, the reason I had tried this again at all was that I dimly remembered having had "issues" with the multi-argument form of system() recently (on Windows):  I had to pass a double-quoted value (a filename with spaces) through to another script (outside of my control), which itself was then calling system(). Due to the way the script was written, one level of quoting was being removed, which is why the argument itself needed to contain double quotes around the filename.

      I had tried something like this

      my $outfile = '\"c:\Documents and Settings\foo\my file\"'; my @command = ( $^X, '-leprint for @ARGV', '--', '-o', $outfile ); 0 == system @command or die "system @command failed: $?";

      expecting that $outfile would automatically get an outer pair of double quotes added around the specified value. However, it didn't, producing

      c:\>perl t.pl -o "c:\Documents and Settings\foo\my file"

      while the corresponding one-argument form works fine

      my $outfile = '\"c:\Documents and Settings\foo\my file\"'; my $command = qq($^X -le"print for \@ARGV" -- -o "$outfile"); 0 == system $command or die "system $command failed: $?"; __END__ -o "c:\Documents and Settings\foo\my file"

      Seems kind of inconsequent to me that with the multi-argument form, you still have to fiddle with the quoting yourself, i.e. add extra outer double quotes like this

      my $outfile = '"\"c:\Documents and Settings\foo\my file\""';

      to get the correct behavior. Why isn't this being done by Perl, when other values are apparently being quoted properly?

        Your problems surface from the assumption that there's a standard way of escaping quotes in Windows. Is there one? There didn't used to be.

Re^5: quoting issue with system command (echo.exe)
by tye (Sage) on May 13, 2009 at 03:55 UTC

    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        

      Change the test script to use 'cmd', '/c', 'echo'

      For the record, yes, this produces the expected (quoted) output.