Domanda

I used exec() function to run the magento commands.

As exec() is not recommended used the below code .

class Test{
 protected $_shell;
 public function __construct(
    \Magento\Framework\ShellInterface $shell
){
    $this->_shell = $shell;
}
public function execute() {
    $this->_shell->execute("php bin/magento cache:disable");
}

The above code not working as expected, can someone help me with the above requirement.

I am looking for running the cli commands without using SSH.

Thanks!!

È stato utile?

Soluzione

Replace your code like below

use Magento\Framework\Shell;
use Magento\Framework\Shell\CommandRenderer;
class Test{
protected $_shell;
public function __construct(
 .....
 .....
){
  ....
  $this->_shell = new Shell(new CommandRenderer());
}
public function execute() {
  $this->_shell->execute("php bin/magento cache:disable");
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange
scroll top