Hello,
I am trying to execute a .exe program through PHP. The basic function i am trying to use is exec.
The program needs the path of a particular directory as its arguement. But the path has spaces and this is not getting recognised by the command.
Here is the code..
//Code for executing the ReportSender
$target_path = "\"E:/Naresh/C++ projects/Report Requests\"";
$exelocation = "\"E:/Naresh/C++ Projects/ReportSender/ReportSender/bin/Release/ReportSender.exe\"";
echo "COMMAND IS $cmd \n";
$cmd = $exelocation." ".$target_path;
exec($cmd,$return_val);
print_r($return_val);
//Code ended..
The output is
//output for the program
COMMAND IS "E:/Naresh/C++ projects/ReportSender/ReportSender/bin/Release/ReportS
ender.exe" "E:/Naresh/C++ projects/Report Requests"
Array
(
)
//out put ended..
Now i have copied and pasted the same command and i was successful in executing through commandline.
Since there are spaces in the command given, i have included double quotes (") to include them.
I have also tried placing escape characters for space instead of putting whole things in quotes.. still no use..
Can anyone help me with this??
NEED HELP ON EXEC function
Moderator: General Moderators
-
filippo.toso
- Forum Commoner
- Posts: 30
- Joined: Thu Aug 07, 2008 7:18 am
- Location: Italy
- Contact:
Re: NEED HELP ON EXEC function
Try with this variables:
Code: Select all
$target_path = '"E:\\Naresh\\C++ projects\\Report Requests"';
$exelocation = '"E:\\Naresh\\C++ Projects\\ReportSender\\ReportSender\\bin\\Release\\ReportSender.exe"';NEED HELP ON EXEC function
i have tried with the same.. the command that appears on the output is exactly the same as the command i need but still no execution done.. I have copied the output and pasted on the common commandline provided by windows..there it gets executed..
I have also checked the php.ini file to see if the safe_exec mode is on. No its off..
For information i am posting the output of the program
//output of the program starts here
COMMAND IS "E:\Naresh\C++ Projects\ReportSender\ReportSender\bin\Release\ReportS
ender.exe" "E:\Naresh\C++ projects\Report Requests"
Array
(
)
//output of the program ends
I have also checked the php.ini file to see if the safe_exec mode is on. No its off..
For information i am posting the output of the program
//output of the program starts here
COMMAND IS "E:\Naresh\C++ Projects\ReportSender\ReportSender\bin\Release\ReportS
ender.exe" "E:\Naresh\C++ projects\Report Requests"
Array
(
)
//output of the program ends
-
filippo.toso
- Forum Commoner
- Posts: 30
- Joined: Thu Aug 07, 2008 7:18 am
- Location: Italy
- Contact:
Re: NEED HELP ON EXEC function
Which web server are you using?
Are you sure that the user is running PHP has the required privileges to execute the command?
Have you tried to run another command line tool (i.e. dir /s) to verify if the code works correctly?
Are you sure that the user is running PHP has the required privileges to execute the command?
Have you tried to run another command line tool (i.e. dir /s) to verify if the code works correctly?
NEED HELP ON EXEC function
I am using apache 2.2.8 server with PHP version 5.2.5 enabled with ssl. I have executed someother programs with the code and could successfully do it. The problem is with this command only. The output i have posted in the forum is the output from the commandline.
i wrote the code and in command line i typed "php -f filename.php" . Was able to execute other php files with the same command.
i wrote the code and in command line i typed "php -f filename.php" . Was able to execute other php files with the same command.