Executing an application whose directory path contains blank spaces

From: Jean-Marc Molina (jmmolina_at_PASDEPOURRIEL-free.fr)
Date: 01/20/05


Date: Thu, 20 Jan 2005 09:58:30 +0100

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