Re: Executing an application whose directory path contains blank spaces
From: Paul Barfoot (Paul_at_theglobalfamily.fsworld.co.uk)
Date: 01/20/05
- Next message: Bob Bedford: "advice needed"
- Previous message: Ivan Dumlija: "Output forsing?"
- In reply to: Jean-Marc Molina: "Executing an application whose directory path contains blank spaces"
- Next in thread: Jean-Marc Molina: "Re: Executing an application whose directory path contains blank spaces"
- Reply: Jean-Marc Molina: "Re: Executing an application whose directory path contains blank spaces"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
>
- Next message: Bob Bedford: "advice needed"
- Previous message: Ivan Dumlija: "Output forsing?"
- In reply to: Jean-Marc Molina: "Executing an application whose directory path contains blank spaces"
- Next in thread: Jean-Marc Molina: "Re: Executing an application whose directory path contains blank spaces"
- Reply: Jean-Marc Molina: "Re: Executing an application whose directory path contains blank spaces"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|