Skip to content

Commit

Permalink
refactor pid command
Browse files Browse the repository at this point in the history
  • Loading branch information
asciito committed Oct 23, 2023
1 parent 02d7d11 commit e9c9784
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions app/Commands/DriverManagerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ class DriverManagerCommand extends Command

protected array $commands = [
'start' => './chromedriver --log-level=ALL --port={port} &',
'pid' => "ps aux | grep '[c]hromedriver --log-level=ALL --port={port}' | awk '{print $2}'",
'pids' => "ps aux | grep '[c]hromedriver --log-level=ALL' | awk '{print $2}'",
'pid' => "ps aux | grep '[c]hromedriver --log-level=ALL {port}' | awk '{print $2}'",
'stop' => 'kill -9 {pid}',
];
Expand Down Expand Up @@ -150,7 +149,8 @@ protected function status(string $port): int

public function kill(): int
{
$result = $this->command($this->commands['pids'])->run();
$result = $this->command(Str::replace('{port}', '', $this->commands['pid']))->run();
;

if (empty($result->output())) {
warning("There' no servers to kill");
Expand Down Expand Up @@ -182,7 +182,7 @@ protected function command(string $cmd): PendingProcess

protected function getProcessID(string $port): ?int
{
$process = $this->command(Str::replace('{port}', $port, $this->commands['pid']))->run();
$process = $this->command(Str::replace('{port}', '--port='.$port, $this->commands['pid']))->run();

return (int) trim($process->output()) ?: null;
}
Expand Down

0 comments on commit e9c9784

Please sign in to comment.