Description
CommandRunnerTask cannot be used: every execution fails, whatever the command.
Reproduction
clever_age_process:
configurations:
demo.command_runner:
tasks:
run:
service: '@CleverAge\ProcessBundle\Task\Process\CommandRunnerTask'
options:
commandline: ['echo', 'hello']
outputs: [debug]
debug:
service: '@CleverAge\ProcessBundle\Task\Debug\DebugTask'
$ bin/console cleverage:process:execute demo.command_runner
Starting process 'demo.command_runner'...
CRITICAL [cleverage_process_task] Invalid option "cwd" passed to "Symfony\Component\Process\Process::setOptions()".
Supported options are "blocking_pipes", "create_process_group", "create_new_console".
A string commandline (allowed by setAllowedTypes('commandline', ['string', 'array'])) fails even earlier:
Symfony\Component\Process\Process::__construct(): Argument #1 ($command) must be of type array, string given,
called in src/Task/Process/CommandRunnerTask.php on line 35
Tested on main (f8201fe), PHP 8.5, Symfony 7.4. CommandRunnerTask.php is unchanged on current main (e70a620).
Cause
In CommandRunnerTask::execute():
$process->setOptions($options) receives the whole resolved options array (commandline, cwd, env, timeout, options). Process::setOptions() only accepts blocking_pipes, create_process_group and create_new_console. The intent was to pass the task's options option: $options['options'].
new Process() only accepts an array command. A string commandline must go through Process::fromShellCommandline().
The reference documentation added in #188 already describes the failure in its Notes section.
Proposed fix
- pass only
$options['options'] to Process::setOptions(), and only when it is not null;
- use
Process::fromShellCommandline() when commandline is a string;
- validate the types of
cwd, env, timeout and options;
- update
docs/reference/tasks/command_runner_task.md: remove the Notes section and document options.
Fixed by #187.
Requirements
Breaking changes
None: every configuration of this task currently fails, so no working setup can break.
Description
CommandRunnerTaskcannot be used: every execution fails, whatever the command.Reproduction
A string
commandline(allowed bysetAllowedTypes('commandline', ['string', 'array'])) fails even earlier:Tested on
main(f8201fe), PHP 8.5, Symfony 7.4.CommandRunnerTask.phpis unchanged on currentmain(e70a620).Cause
In
CommandRunnerTask::execute():$process->setOptions($options)receives the whole resolved options array (commandline,cwd,env,timeout,options).Process::setOptions()only acceptsblocking_pipes,create_process_groupandcreate_new_console. The intent was to pass the task'soptionsoption:$options['options'].new Process()only accepts anarraycommand. Astringcommandline must go throughProcess::fromShellCommandline().The reference documentation added in #188 already describes the failure in its Notes section.
Proposed fix
$options['options']toProcess::setOptions(), and only when it is notnull;Process::fromShellCommandline()whencommandlineis a string;cwd,env,timeoutandoptions;docs/reference/tasks/command_runner_task.md: remove the Notes section and documentoptions.Fixed by #187.
Requirements
Breaking changes
None: every configuration of this task currently fails, so no working setup can break.