Re: Executing an application whose directory path contains blank spaces

From: Paul Barfoot (Paul_at_theglobalfamily.fsworld.co.uk)
Date: 01/20/05


Date: Thu, 20 Jan 2005 17:18:38 -0000

Jean-Marc

I have found two ways around this problem:

1. Accept that paths with spaces in are going to get treated as two
arguments and work around it - change line in php script to:

system ('"C:\test copy\mycopy" /B C:\test copy\folder1\file1 C:\test
copy\folder2\file2');

                       command %1 %2 %3
%4 %5

and then alter your batch file like this:

copy %1 "%2 %3" "%4 %5"

Note spaces between %2 & %3, and between %4 & %5

2. Create your batch file on the fly in the php script - I think this is
neater as you could pass source and destination filepaths in as variables:

<?
$handle=fopen("C:/test copy/mycopy.bat", "w");
$command = "copy /B \"C:\\test copy\\folder1\\file1\" \"C:\\test
copy\\folder1\\file2\"";
//echo "$command<br />\n"; //used for testing
fwrite($handle, $command);
system ("\"C:/test copy/mycopy.bat\""); //note I have escaped the " and used
forward slashes in the path
fclose($handle);
?>

Take your pick!

-- 
Paul Barfoot
"Jean-Marc Molina" <jmmolina@PASDEPOURRIEL-free.fr> wrote in message 
news:41ef72b6$0$9969$636a15ce@news.free.fr...
> Hello,
>
> I can't find a way to execute a Windows application, whose directory path
> contains blank spaces, from a PHP script. I also wonder if the problem
> happens under Linux and other OS.
>
> Working dir : "C:\test copy"
>
> "copy.php" PHP script :
> <?php
>
> system ('"C:\test copy\mycopy" /B "C:\test copy\folder1\file1" "C:\test
> copy\folder2\file2"');
>
>>
>
> mycopy.bat batch :
> copy %1 %2 %3
>
> Executign this script I get the following error message :
> « C:\>php "test copy\copy.php
> 'C:\test' is not recognized as an internal or external command,
> operable program or batch file. »
>
> If I replace « test copy » by « test » or « test_copy », it works.
>
> The problem doesn't happen if the command parameters are not double quoted 
> :
>
> <?php
>
> system ('"C:\test copy\mycopy" /B');
>
>>
>
> Note that you can just copy & paste these commands and see how they work 
> in
> a DOS command window.
>
> How should I transform these blank spaces characters ? For example in a 
> URL
> you replace blank spaces by « %20 »...
>
> The general idea is to execute an application located in the « "C:\Program
> Files" directory. On the 
> <http://www.php.net/manual/en/function.system.php>
> page of the PHP manual someone proposed a solution but its command line
> doesn't involve double quoted parameters.
>
> --
> Jean-Marc.
> 


Relevant Pages

  • Re: xp_cmdshell default path (system32) problem
    ... building a batch file in code and then ... it will NOT actually execute the delete if the patch I supply is not valid. ... I'm use xp_cmdShell to execute "erase" command like ...
    (microsoft.public.sqlserver.programming)
  • Re: Perfmon and batch file
    ... > event viewer and run command file. ... > but no execute the cmd file or execute it but not execute the ... You are probably making some assumptions in your batch file ... @echo off ...
    (microsoft.public.windows.server.general)
  • Re: SEPKILL /im SMC.EXE /f
    ... Subject: SEPKILL /im SMC.EXE /f ... Save the following as a batch file and execute it ... If done from a batch file the command is completed only when the process is stopped. ...
    (Bugtraq)
  • BatchFile/CmdScript to run Ad-aware, Spybot, AV s/w
    ... I would like a batch file or command script that would ... Execute Ad-aware, ...
    (microsoft.public.windowsxp.security_admin)
  • Re: import .cab Analysis Services DB on website
    ... which user account is used to execute the batch file? ... I tried to run the msmdarch tool within an batch file from an execution ... it comes to the msmdarch command. ...
    (microsoft.public.sqlserver.olap)