[Process] Accept command line arrays and per-run env vars, fixing signaling and escaping#21474
Merged
fabpot merged 1 commit intosymfony:masterfrom Feb 8, 2017
Merged
Conversation
ca8cba7 to
ff267c9
Compare
fabpot
added a commit
that referenced
this pull request
Jan 31, 2017
This PR was merged into the 2.7 branch. Discussion ---------- [Console] Fix too strict test | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - required to make #21474 green in cross versions tests Commits ------- ee4b3e2 [Console] Fix too strict test
dceca99 to
8dbcc59
Compare
…naling and escaping
8dbcc59 to
330b61f
Compare
Member
|
Thank you @nicolas-grekas. |
fabpot
added a commit
that referenced
this pull request
Feb 8, 2017
…ars, fixing signaling and escaping (nicolas-grekas) This PR was merged into the 3.3-dev branch. Discussion ---------- [Process] Accept command line arrays and per-run env vars, fixing signaling and escaping | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | #12488, #11972, #10025, #11335, #5759, #5030, #19993, #10486 | License | MIT | Doc PR | - I think I found a way to fix this network of issues once for all. Of all the linked ones, only the last two are still open: the remaining were closed in dead ends. Instead of trying to make `ProcessUtil::escapeArgument` work correctly on Windows - which is impossible as discussed in #21347 - this PR deprecates it in favor of a more powerful approach. Depending on the use case: - when a simple command should be run, `Process` now accepts an array of arguments (the "binary" being the first arg). Making this the responsibility of `Process` (instead of `ProcessBuilder`) gives two benefits: - escape becomes an internal detail that doesn't leak - thus can't be misused ([see here](#21347 (comment))) - since we know we're running a single command, we can prefix it automatically by "exec" - thus fixing a long standing issue with signaling ```php $p = new Process(array('php', '-r', 'echo 123;')); echo $p->getCommandLine(); // displays on Linux: // exec 'php' '-r' 'echo 123;' ``` - when a shell expression is required, passing a string is still allowed. To make it easy and look-like sql prepared statements, env vars can be used when running the command. Since the shell is OS-specific (think Windows vs Linux) - this PR assumes no portability, so one should just use each shell's specific syntax. From the fixtures: ```php $env = array('FOO' => 'Foo', 'BAR' => 'Bar'); $cmd = '\\' === DIRECTORY_SEPARATOR ? 'echo !FOO! !BAR! !BAZ!' : 'echo $FOO $BAR $BAZ'; $p = new Process($cmd, null, $env); $p->run(null, array('BAR' => 'baR', 'BAZ' => 'baZ')); $this->assertSame('Foo baR baZ', rtrim($p->getOutput())); $this->assertSame($env, $p->getEnv()); ``` Commits ------- 330b61f [Process] Accept command line arrays and per-run env vars, fixing signaling and escaping
Contributor
|
Was reviewing :) 👍 anyway |
|
Keep in mind that this can break things: 1) when Maybe this should at least be mentioned in changelog? I should probably open a separate issue for this, I'm just not so sure this would help. |
Member
Author
|
Please open an issue with a reproducer |
This was referenced Apr 22, 2017
Contributor
|
This isn't going to be tagged for another eight months 😞 |
Member
Author
|
This will be released next month in 3.3 |
Contributor
|
I guess someone set the due by date incorrectly, then. For what it's worth, I can confirm this fixes my issue. |
Member
Author
|
the due date is set the end-of-support day :) |
Merged
fabpot
added a commit
to sensiolabs/SensioGeneratorBundle
that referenced
this pull request
Jul 17, 2017
…avier) This PR was squashed before being merged into the 3.1.x-dev branch (closes #564). Discussion ---------- Fix deprecation notice in test (ProcessBuilder) Backward- and forward-compatible fix for ``` Remaining deprecation notices (1) The Symfony\Component\Process\ProcessBuilder class is deprecated since version 3.4 and will be removed in 4.0. Use the Process class instead: 1x 1x in KernelManipulatorTest::testAddToArray from Sensio\Bundle\GeneratorBundle\Tests\Manipulator ``` Relevant commits: - symfony/process@201c3bd (PR symfony/symfony#23111) - symfony/process@e34416d (PR symfony/symfony#21474) - symfony/process@0743280 (PR symfony/symfony#23498) I also considered the simpler test `\Symfony\Component\HttpKernel\Kernel::VERSION_ID >= 30400` but it seems less reliable (version constant _vs_ code, possibly different versions of `symfony/http-kernel` _vs_ `symfony/process`). Commits ------- 5fe7d3e Fix deprecation notice in test (ProcessBuilder)
JayeTurn
added a commit
to JayeTurn/SensioGeneratorBundle
that referenced
this pull request
Jun 9, 2025
…avier)
This PR was squashed before being merged into the 3.1.x-dev branch (closes #564).
Discussion
----------
Fix deprecation notice in test (ProcessBuilder)
Backward- and forward-compatible fix for
```
Remaining deprecation notices (1)
The Symfony\Component\Process\ProcessBuilder class is deprecated since version 3.4 and will be removed in 4.0. Use the Process class instead: 1x
1x in KernelManipulatorTest::testAddToArray from Sensio\Bundle\GeneratorBundle\Tests\Manipulator
```
Relevant commits:
- symfony/process@201c3bd (PR symfony/symfony#23111)
- symfony/process@e34416d (PR symfony/symfony#21474)
- symfony/process@0743280 (PR symfony/symfony#23498)
I also considered the simpler test `\Symfony\Component\HttpKernel\Kernel::VERSION_ID >= 30400` but it seems less reliable (version constant _vs_ code, possibly different versions of `symfony/http-kernel` _vs_ `symfony/process`).
Commits
-------
5fe7d3e Fix deprecation notice in test (ProcessBuilder)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I think I found a way to fix this network of issues once for all.
Of all the linked ones, only the last two are still open: the remaining were closed in dead ends.
Instead of trying to make
ProcessUtil::escapeArgumentwork correctly on Windows - which is impossible as discussed in #21347 - this PR deprecates it in favor of a more powerful approach.Depending on the use case:
Processnow accepts an array of arguments (the "binary" being the first arg). Making this the responsibility ofProcess(instead ofProcessBuilder) gives two benefits:From the fixtures: