Daniel Częstki
Daniel Częstki

Reputation: 99

How run exec command with Symfony process

I have such code where I run identify command direct from PHP:

$cmd = "identify -quiet -verbose '{$filePath}' ";
@exec($cmd, $data);

This is working fine and I get array data from identify with image specification.

But how can I run this command with Symfony process. Everything I tried do not work

$process = new Process(['identify', "-quiet -verbose '$filePath'"]);
$process->run();

// executes after the command finishes
if (!$process->isSuccessful()) {
   throw new ProcessFailedException($process);
}

$data = $process->getOutput();

I get exception with message:

The command "'identify' '-quiet -verbose '\''/home/daniel/Web/project/web/var/assets/177713 - file.jpg'\'''" failed. Exit Code: 1(General error) Working directory: / Output: ================ Error Output: ================ identify-im6.q16: unrecognized option `-quiet -verbose '/home/daniel/Web/project/web/var/assets/177713 - file.jpg'' @ error/identify.c/IdentifyImageCommand/790

How can I run this command from Symfony process ?

Upvotes: 0

Views: 39

Answers (1)

Daniel Częstki
Daniel Częstki

Reputation: 99

this is working fine

$cmd = "identify -quiet -verbose '{$filePath}' ";
$process = Process::fromShellCommandline($cmd);
$process->run();

// executes after the command finishes
if (!$process->isSuccessful()) {
   throw new ProcessFailedException($process);
}

$data = $process->getOutput();
$data = exlode("\n", $data);

Upvotes: 1

Related Questions