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

I have to put quotes around the two filenames with a space in
between to create the database. $contig is the query. Also, yes
$maid_dir has can have spaces in it.

What is the best way to get around that?

LomSpace
  • Comment on Re^2: quoting issue with system command

Replies are listed 'Best First'.
Re^3: quoting issue with system command
by John M. Dlugosz (Monsignor) on May 13, 2009 at 16:02 UTC
    Put the exe name in quotes, too:
    "D:\Program Files\foo.exe" arg1 arg2 "file_name with spaces.txt"
    The logic of system's argument processing is supposed to make sense on Unix, with underlying OS primitives that work in the same way. But it's a mess on Windows, where the documented meaning is implemented to some degree. Point is, it takes different code paths depending on the form, with different behavior. It's been a while since I looked at it. But if it calls the CMD.exe shell with the whole thing as a string, it behaves the same way as on the command line, as I showed. If it tries to call CreateProcess directly, the exe file name is a separate argument to that.

    I suppose I should refresh my knowledge before writing anything that makes use of that feature myself.

      So something like this:

      my $command = “c:\\blast\bin\\blastall.exe" -p blastn -d "$hu_seq $hd_seq" -i "$contig" -o $alignment”;
      print "$command\n";
      system($command);
        Better:
        my @command = ("c:\\blast\bin\\blastall.exe", -p => 'blastn', -d => "$hu_seq $hd_seq", -i => $contig, -o => $alignment, ); system(@command);

        Note: You've got a problem if -d expects space-separated paths if the paths have spaces in them.

        You are missing putting delimiters around the whole thing.
      Oh, I am using it on Windows. My path is :

      $hu_seq is 'I:\13414 Ccl9 (88)\sequencing\13414_hu.fa'
      $hd_seq is 'I:\13414 Ccl9 (88)\sequencing\13414_hd.fa'

      This is what I am passing to the system command.
      my @command2 =('c:\\blast\\bin\\blastall.exe','-p', 'blastn','-d',"$hu_seq $hd_seq",'-i', $contig,'-o', $alignment);

      I am getting the following error message:

      NULL_Caption ERROR: Could not open i:\13414
      NULL_Caption ERROR: Arguments must start with '-' (the offending argument #7 was: 'Ccl9')

      I think that this is why I am unable to build the blastsearchable db.
      How do I get around those space in path to the variable?
      Thanks!
      LomSpace