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\fi le1" "C:\test
copy\folder2\fi le2"');
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. 9 6681
*** Jean-Marc Molina wrote/escribió (Thu, 20 Jan 2005 09:58:30 +0100): mycopy.bat batch : copy %1 %2 %3
You're missing quotes in the batch file?
copy "%1" "%2" "%3"
--
-- Álvaro G. Vicario - Burgos, Spain
-- Thank you for not e-mailing me your questions
--
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\fi le1 C:\test
copy\folder2\fi le2');
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<b r />\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" <jm******@PASDE POURRIEL-free.fr> wrote in message
news:41******** **************@ 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\fi le1" "C:\test copy\folder2\fi le2"');
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.
Alvaro G Vicario a écrit/wrote : You're missing quotes in the batch file?
copy "%1" "%2" "%3"
No, my parameters are already quoted, I think it even double-double-quotes
them :).
Command line :
« C:\>php "C:\test copy\copy.php"
'C:\test' is not recognized as an internal or external command,
operable program or batch file. »
--
Jean-Marc.
Paul Barfoot a écrit/wrote : $command = "copy /B \"C:\\test copy\\folder1\\ file1\" \"C:\\test copy\\folder1\\ file2\"";
Thanks but I supposed « copy » was located in a path containing blank
spaces, like "C:\Program Files" for example, that's why I used a "C:\test
copy" test folder, this was just an example.
--
Jean-Marc.
"Jean-Marc Molina" <jm******@PASDE POURRIEL-free.fr> wrote in message
news:41******** **************@ news.free.fr... Alvaro G Vicario a écrit/wrote : You're missing quotes in the batch file?
copy "%1" "%2" "%3"
No, my parameters are already quoted, I think it even double-double-quotes them :).
Command line :
« C:\>php "C:\test copy\copy.php" 'C:\test' is not recognized as an internal or external command, operable program or batch file. »
-- Jean-Marc.
They have to be quoted again in the batch file. Otherwise cmd isn't going to
parse the line correctly.
Chung Leong a écrit/wrote : They have to be quoted again in the batch file. Otherwise cmd isn't going to parse the line correctly.
Did you try it ? Does it work ? What's your output ? What's your OS ?
I tried it. It doesn't work. I get below output and my OS is Windows 2000
Pro.
Try to execute the following "copy.php" PHP script :
<?php
system ('"' . dirname ($_SERVER ['PHP_SELF']) . '\mycopy.bat" /B "C:\test
copy\folder1\fi le1" "C:\test copy\folder2\fi le2"');
?>
mycopy.bat batch file :
copy "%1" "%2" "%3"
Output :
« >php "C:\test copy\copy.php"
'C:\test' is not recognized as an internal or external command,
operable program or batch file. »
--
Jean-Marc.
Jean-Marc
Try executing the command you want directly in a Win2000 command window.
Where do you need to put quotes to get that to work? Then put quotes in
either the batch file or the PHP script to mirror this.
That was how I came to the solution I offered in my earlier post. If I
quoted the source and destination filenames in PHP then the system command
didn't work, but if I didn't put quotes around them the parameters were
treated as 5 variables instead of 3!
Regards
--
Paul Barfoot
"Jean-Marc Molina" <jm******@PASDE POURRIEL-free.fr> wrote in message
news:41******** *************** @news.wanadoo.f r... Chung Leong a écrit/wrote : They have to be quoted again in the batch file. Otherwise cmd isn't going to parse the line correctly.
Did you try it ? Does it work ? What's your output ? What's your OS ?
I tried it. It doesn't work. I get below output and my OS is Windows 2000 Pro.
Try to execute the following "copy.php" PHP script : <?php
system ('"' . dirname ($_SERVER ['PHP_SELF']) . '\mycopy.bat" /B "C:\test copy\folder1\fi le1" "C:\test copy\folder2\fi le2"');
?>
mycopy.bat batch file : copy "%1" "%2" "%3"
Output : « >php "C:\test copy\copy.php" 'C:\test' is not recognized as an internal or external command, operable program or batch file. »
-- Jean-Marc.
"Jean-Marc Molina" <jm******@PASDE POURRIEL-free.fr> wrote in message
news:41******** *************** @news.wanadoo.f r... Chung Leong a écrit/wrote : They have to be quoted again in the batch file. Otherwise cmd isn't going to parse the line correctly.
Did you try it ? Does it work ? What's your output ? What's your OS ?
I tried it. It doesn't work. I get below output and my OS is Windows 2000 Pro.
Try to execute the following "copy.php" PHP script : <?php
system ('"' . dirname ($_SERVER ['PHP_SELF']) . '\mycopy.bat" /B "C:\test copy\folder1\fi le1" "C:\test copy\folder2\fi le2"');
?>
mycopy.bat batch file : copy "%1" "%2" "%3"
Output : « >php "C:\test copy\copy.php" 'C:\test' is not recognized as an internal or external command, operable program or batch file. »
My apology. I was wrong about the quotes. Didn't realize that cmd is smart
enough to put quotes around a parameter when it expands %1, %2.
The problem, it appears, is caused by a broken implementation of system() in
the C library. To get around, use cmd.exe to parse the command.
Example:
test.bat:
echo %1
echo %2
test.php:
echo `cmd /C ""C:\\test copy\\test.bat" "C:\\Progra m files" "C:\\Docume nts
and settings""`
The first and last quotation marks enclose the command, while the others
enclose the parameters. Need to escape slashes here because I'm using
backtick.
Hope that's more useful advise.
Chung Leong a écrit/wrote : The problem, it appears, is caused by a broken implementation of system() in the C library. To get around, use cmd.exe to parse the command.
Works like a charm !
New copy.php PHP script :
<?php
$cmd = '"' . dirname ($_SERVER ['PHP_SELF']) . '\mycopy.bat" /B "C:\test
copy\folder1\fi le1" "C:\test copy\folder2\fi le2"';
system ("cmd /C \"$cmd\"");
?>
New mycopy.bat :
copy %1 %2 %3
Thanks !
--
Jean-Marc. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: HP |
last post by:
I am using urllib.urlretrieve() to download a file from a web site.
THe trouble is that the file name has spaces in it,
such as "string string1 foo.doc".
The statement:
urllib.urlretrieve("http://website.com/path/string string1 foo.doc",
"local_file");
produces local_file which contains the following one line:
<html><head><title>Error</title></head><body>The parameter is
|
by: Darren Dale |
last post by:
Some time ago I asked about executing a python program or script. For
windows, I was informed that the .py extension could be added to some list
of executable extensions, and then I could just type "mycode" instead of
"python mycode.py". Great advice, worked like a charm.
I recently jumped ship, and have been running Gentoo Linux for about two
months. Is it possible to get the same behavior on Linux? I thought it
would have something to...
|
by: Jennica Humphrey |
last post by:
Hi, just as the topic says, how do I get the names of files within a
directory? The examples I've seen appear to be *nix-specific. I'm
using .NET but would like to avoid MFC if at all possible.
|
by: JS |
last post by:
I have v8.1 fix 5 installed on windows 2k.
I compiled a stored procedure in development environment, then used
the get routine command to generate the file.
I transferred the file to second test environment with same fixpack
level, but no compiler or development environment installed.
I issued put routine in second test environment and command succeeded
but when i try and run the stored proc with call command, db2 comes
back with sql0444...
|
by: (Pete Cresswell) |
last post by:
I've got a .BAT file that I use for executing various MS Access apps that I
wrote way back in the days of 2.0.
It's evolved over time, but it still contains a number of possible paths to
MSACCESS.EXE, tries them all, takes the first one it finds, and dies if none is
found.
Seems to me like at some time or another I was able to clone this .BAT file and
implement it with no path. Something about MSACCESS being a registered
application.
| |
by: Timothy Shih |
last post by:
Hi,
I am having a freezing issue with my application. My application serves
several remotable objects, all of which must be initialized before their
use. Furthermore, some of them depend on each other. On my application
startup, I configure the objects usting the RemotingConfiguration class to
load the config file. Then I "ping" each of the objects to call their
constructors. This all works fine if no one is attempting to connect at the...
|
by: rtilley |
last post by:
# Spaces are present before and after the XXX
filename = ' XXX '
new_filename = filename.strip()
if new_filename != filename:
print filename
Macs allow these spaces in file and folder names. Which is OK. The
problem arises when the file or folder is copied to a PC running Windows
|
by: comp.lang.php |
last post by:
Once again, I thought my class method deleteZip() would do the trick,
but it never deletes any .zip* file found in a directory:
/**
* Delete any latent ZIP files found in this album. This method is to
be inherited by all listing classes to allow for
* list-wide deletion of latent server-created ZIP files for security
purposes
*
|
by: Jorgen Bodde |
last post by:
Hi all,
This is slightly OT but it drives me nuts. Whenever I create a
shortcut in the start menu (in Windows) of a python script, it will
only execute it when the path where the script resides in contains no
spaces. For example;
d:\src\app\app.py
If I drag that to the Start Menu it can be executed fine.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |