Hi I am attempting to execute a jar from PHP 5
Here is the code I am executing:
$command = '"java -jar WEB-INF\\lib\\FileReceiver.jar '.$address.' '.$service_port.' \"'.$command.'\" \"'.$filePath.'\""';
exec($command, $out);
But the jar is not being executed. I had logged the $command variable in firebug and took the output and inserted into the code such as:
exec("java -jar WEB-INF\lib\FileReceiver.jar 127.0.1.1 2018 \"docs/document.txt \" \"C:\\apache-tomcat-7.0.26\\webapps\\test\\downloads\\doument.txt\"", $out);
gives the correct output. I dont understand why hard coding it works but the variable which contains the same information does not.
Could someone help me out?
Thanks
try like this
$command = escapeshellarg($address).' '.escapeshellarg($service_port).' '.escapeshellarg($command).' '.escapeshellarg($filePath).' ';
exec('java -jar WEB-INF\\lib\\FileReceiver.jar '.$command, $out);
You're over-escaping the double quotes in your first snippet.
You're using single quotes for the literal string delimiter, so you don't need to escape the double quote.
Also, the final '\""'
should be '"'
$adress
$service_port
$command
and$filepath
have the right values - NoName 2012-04-04 02:33