From 402a63d7385de0c64595eabd6d9402c27418dc93 Mon Sep 17 00:00:00 2001 From: guanguans Date: Thu, 16 Jan 2025 18:34:52 +0800 Subject: [PATCH] refactor(WithRunable): Simplify sudo password handling - Remove unnecessary echo command from sudo password handling - Update Process instantiation to streamline the command line - Maintain sudo password input functionality for better clarity --- src/Concerns/WithRunable.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Concerns/WithRunable.php b/src/Concerns/WithRunable.php index 4fbd9b9..06bd40d 100644 --- a/src/Concerns/WithRunable.php +++ b/src/Concerns/WithRunable.php @@ -60,13 +60,16 @@ protected function createProcess($withOptions = []): Process : new Process(array_merge([$this->soarBinary], $this->clone()->mergeOptions($withOptions)->getNormalizedOptions())); if ($this->shouldApplySudoPassword()) { + // $process = Process::fromShellCommandline(\sprintf( + // 'echo %s | sudo -S %s', + // $this->getEscapedSudoPassword(), + // $process->getCommandLine() + // )); + $process = Process::fromShellCommandline(\sprintf( - 'echo %s | sudo -S %s', - $this->getEscapedSudoPassword(), + 'sudo -S %s', $process->getCommandLine() - )); - - // $process->setInput($this->getSudoPassword()); + ))->setInput($this->getSudoPassword()); } if (\is_callable($this->processTapper)) {