Skip to content

Commit

Permalink
[Process] Stop the process correctly even if underlying input stream …
Browse files Browse the repository at this point in the history
…is not closed:

While checking a process to end, on posix system, process component only checks if pipes are still open, this fix
ensure that if the process is terminated it correctly return, even if the underlying pipe is not closed.

It can be useful when using \STDIN as a input stream as it will always be open
  • Loading branch information
joelwurtz committed May 17, 2023
1 parent 4b842fc commit e3c46cc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ public function wait(callable $callback = null)

do {
$this->checkTimeout();
$running = '\\' === \DIRECTORY_SEPARATOR ? $this->isRunning() : $this->processPipes->areOpen();
$running = $this->isRunning() && ('\\' === \DIRECTORY_SEPARATOR || $this->processPipes->areOpen());
$this->readPipes($running, '\\' !== \DIRECTORY_SEPARATOR || !$running);
} while ($running);

Expand Down
10 changes: 10 additions & 0 deletions Tests/ProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1538,6 +1538,16 @@ public function testEnvCaseInsensitiveOnWindows()
}
}

public function testNotTerminableInputPipe()
{
$process = $this->getProcess('echo foo');
$process->setInput(\STDIN);
$process->start();
$process->setTimeout(2);
$process->wait();
$this->assertFalse($process->isRunning());
}

/**
* @param string|array $commandline
* @param mixed $input
Expand Down

0 comments on commit e3c46cc

Please sign in to comment.