From b49bd8b63258b833d6c63b95313b4824067567fa Mon Sep 17 00:00:00 2001 From: Saif Eddin Gmati <29315886+azjezz@users.noreply.github.com> Date: Wed, 1 Dec 2021 19:27:53 +0100 Subject: [PATCH] chore(shell): use exec to avoid spawning a grandchild process (#290) Signed-off-by: azjezz --- src/Psl/Shell/execute.php | 2 ++ tests/unit/Shell/ExecuteTest.php | 10 ++-------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Psl/Shell/execute.php b/src/Psl/Shell/execute.php index a2fc3224..f646c27d 100644 --- a/src/Psl/Shell/execute.php +++ b/src/Psl/Shell/execute.php @@ -143,6 +143,8 @@ static function (array $m) use ( 'bypass_shell' => true, 'blocking_pipes' => false, ]; + } else { + $commandline = Str\format('exec %s', $commandline); } // @codeCoverageIgnoreEnd $descriptor = [ diff --git a/tests/unit/Shell/ExecuteTest.php b/tests/unit/Shell/ExecuteTest.php index 380cd822..ac9ee745 100644 --- a/tests/unit/Shell/ExecuteTest.php +++ b/tests/unit/Shell/ExecuteTest.php @@ -67,16 +67,10 @@ public function testCurrentEnvironmentVariablesArePassedDownToTheProcess(): void public function testWorkingDirectoryIsUsed(): void { - if ('Darwin' === PHP_OS_FAMILY || PHP_OS_FAMILY === 'Windows') { - static::markTestSkipped(); - } - $temp = Env\temp_dir(); + $result = Shell\execute(PHP_BINARY, ['-r', 'echo getcwd();'], $temp); - static::assertSame( - $temp, - Shell\execute(PHP_BINARY, ['-r', 'echo getcwd();'], $temp) - ); + static::assertStringEndsWith($temp, $result); } public function testCurrentDirectoryIsUsedByDefault(): void