Here is a code:
$cmd_make_sprite = '/usr/bin/gm convert /path/thumbs/video{1..353}.jpg -append /path/thumbs/sprite.jpg';
$process = new Process($cmd_make_sprite);
$process->run();
echo $process->getErrorOutput();
When I run this snippet I see this output:
/usr/bin/gm convert: Unable to open file (/path/thumbs/video{1..353}.jpg) [No such file or directory].
I think it happens because video{1..353}.jpg
substitution doesn't work and Symfony Process builder treats this as a regular file name, which doesn't exist of course.
I tried to make a sprite_wrapper.sh
for it:
#!/bin/bash
$@
and use it like this:
$cmd_make_sprite = 'bash sprite_wrapper.sh /usr/bin/gm convert /path/thumbs/video{1..353}.jpg -append /path/thumbs/sprite.jpg';
$process = new Process($cmd_make_sprite);
$process->run();
echo $process->getErrorOutput();
and it works, but I'd like to have a more clean code than that.
Does anyone have some thoughts how to improve it? Thanks in advance.
As you perhaps have guessed, the {x..y}
syntax only works in Bash.
But the default shell of Process
is typically /bin/sh
,
which may not be Bash. That's why your first attempt didn't work.
The intermediary sprite_wrapper.sh
is really ugly,
and unnecessary. You can write like this:
$cmd_make_sprite = 'bash -c "/usr/bin/gm convert /path/thumbs/video{1..353}.jpg -append /path/thumbs/sprite.jpg"';
That is, you can pass Bash code to execute with bash
using the -c "..."
option.