Skip to content

Commit 00792da

Browse files
Write to stderr and stdout synchronously on Windows (#295)
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
1 parent a8de89c commit 00792da

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

agent/build/agent.phar

385 Bytes
Binary file not shown.

agent/build/signature.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7C57EC370DB9656684D0C8325B8D889DDE1D90C286CBD38F9DFA997A96AF1212EA6518E6DE88DA8476F5A7A34FA2D5EBC5BC0914AA7EC73B36FBE53C4ABB3357
1+
679D81B7198B1960B0FD84EECB611AE03AA656CCB75FBEAC6DA3E4C2E8D5A515C2C6A01D213E8BC5D3227D677BE7CB8D442F576D80A09FA71956E26539550DB6

agent/src/OutputWriter.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,29 @@
44

55
use React\Stream\WritableResourceStream;
66

7+
use function fflush;
78
use function Nightwatch\fwrite_all;
89

910
class OutputWriter
1011
{
11-
private WritableResourceStream $loopStream;
12-
1312
/**
14-
* @param resource $stream
13+
* @param resource $syncStream
1514
*/
1615
public function __construct(
1716
private Loop $loop,
18-
private $stream,
17+
private $syncStream,
18+
private ?WritableResourceStream $asyncStream,
1919
) {
20-
$this->loopStream = new WritableResourceStream($stream);
20+
//
2121
}
2222

2323
public function write(string $message): void
2424
{
25-
if ($this->loop->running()) {
26-
$this->loopStream->write($message);
25+
if ($this->loop->running() && $this->asyncStream !== null) {
26+
$this->asyncStream->write($message);
2727
} else {
28-
fwrite_all($this->stream, $message);
28+
fwrite_all($this->syncStream, $message);
29+
fflush($this->syncStream);
2930
}
3031
}
3132
}

agent/src/agent.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use React\EventLoop\StreamSelectLoop;
1313
use React\Socket\ServerInterface;
1414
use React\Socket\TcpServer;
15+
use React\Stream\WritableResourceStream;
1516

1617
use function date;
1718
use function file_get_contents;
@@ -82,8 +83,13 @@
8283
* Logging helpers...
8384
*/
8485

85-
$stdOut = new OutputWriter($loop, STDOUT);
86-
$stdErr = new OutputWriter($loop, STDERR);
86+
[$asyncStdOut, $asyncStdError] = match (PHP_OS_FAMILY) {
87+
'Windows' => [null, null],
88+
default => [new WritableResourceStream(STDOUT), new WritableResourceStream(STDERR)],
89+
};
90+
91+
$stdOut = new OutputWriter($loop, syncStream: STDOUT, asyncStream: $asyncStdOut);
92+
$stdErr = new OutputWriter($loop, syncStream: STDERR, asyncStream: $asyncStdError);
8793

8894
$debug = static function (string $message) use ($verbose, $stdOut): void {
8995
if ($verbose) {

0 commit comments

Comments
 (0)