Page 1 of 1

NEED HELP ON EXEC function

Posted: Thu Aug 07, 2008 11:50 pm
by susrisha
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??

Re: NEED HELP ON EXEC function

Posted: Fri Aug 08, 2008 3:03 am
by filippo.toso
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

Posted: Fri Aug 08, 2008 4:06 am
by susrisha
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

Re: NEED HELP ON EXEC function

Posted: Fri Aug 08, 2008 4:09 am
by filippo.toso
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?

NEED HELP ON EXEC function

Posted: Fri Aug 08, 2008 5:57 am
by susrisha
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.