Skip to content

[Process] Allow running multiple commands at once #43162

@m-vo

Description

@m-vo

Description
When running a lot of small shell commands after each other, the overhead of creating the underlying processes becomes noticeable. It would be handy if the process component would support chaining commands.

Working directly on a Linux/Windows shell you would typically do this:

# Linux
$ foo; bar; baz
$ foo && bar && baz

# Windows
$ foo & bar & baz
$ foo && bar && baz

(Yes there are other chaining operators as well like ||.)

This is currently not possible with the process component.

API Example
I like that Symfony\Component\Process\Process became somewhat immutable now (the command line is baked in after the constructor ran), so the API could maybe look like this:

$process = new Process(['foo']);

// foo; bar
$process = $process->withChainedCommand(['bar']); // returns a new process instance

// foo && bar
$process = $process->withAndChainedCommand(['bar']); // returns a new process instance

What do you think? Is this a worthwhile addition?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions