when i call shell_exec as the following, it doesn’t actually call the php but does sh: and file not found.
shell_exec('"/usr/bin/php ./magento xigen:clicreatecustomer:create -f "' . $contacts['name'] . '" -l "company" -e " ' . $contacts['email'] . '" -p "test123" -w 1 --street "' . $address['Address1'] . '" --city "' . $address['City'] . '" --region " ' . $address['State'] .' " --telephone "00000000" --postcode " '. $address['Zip'].' " -c "' . $customer['entityid'] . '"');
what am I doing wrong? i have tried doing absolute paths also.
2
Answers
Try using an absolute path to
magento
in your command, that could be whatsh
is choking on.EDIT:
Two things:
echo
ing one line from your script and executing it from the shell manually to determine where your shell command is failing. This may help solve your problem entirely.shell_exec
, write them all to a separate file, thensource
that file from the command line.You’re adding too many quote signs.
Therefore, the shell tried to execute a file called "/usr/bin/php ./magento xigen…", and that file, of course, does not exist.
Note that if the address or any other field contains an unquoted single quote, the command will fail. You need to replace "’" with "’" in those fields before running the command.
To debug what is happening, print the contents of the
$cmd
variable, or save it to a file and inspect it.