Can't Execute PHP Script Using PHP Exec

Can't execute PHP script using php exec() (in magento)

Maybe

protected function _runSpider()
{
$command = '$(which php) ' . Mage::getBaseDir() . '/spider.php > ' . Mage::getBaseDir() . '/var/log/out.log');
$result = exec($command);
Mage::log($result);
}

Removing the last & will lock execution of the script instead of passing control back to the interpreter. And since you're piping all of the output to a file, maybe you don't need to pipe the output to null.

By the way, the shell command you mounted won't return any data as you're piping everything to a file or /dev/null. If you need it back to the $result var, remove the > filename part of the code, though exec will only give you the last line of the result and you may need the passthru() function or add an $output var to store every line to an array on the exec function.

php exec() is not executing the command

I already said that I was new to exec() function. After doing some more digging, I came upon 2>&1 which needs to be added at the end of command in exec().

Thanks @mattosmat for pointing it out in the comments too. I did not try this at once because you said it is a Linux command, I am on Windows.

So, what I have discovered, the command is actually executing in the back-end. That is why I could not see it actually running, which I was expecting to happen.

For all of you, who had similar problem, my advise is to use that command. It will point out all the errors and also tell you info/details about execution.

exec('some_command 2>&1', $output);
print_r($output); // to see the response to your command

Thanks for all the help guys, I appreciate it ;)

Can't Execute a PHP file via HTTP

Instead of referencing PHP, I got this to work by executing PHP bin file:

exec('/usr/bin/php process_scan.php 2>&1', $output, $retval);


Related Topics



Leave a reply



Submit