diff --git a/includes/shell/Command.php b/includes/shell/Command.php index d6f95783f0d..d9fa82dfa3e 100644 --- a/includes/shell/Command.php +++ b/includes/shell/Command.php @@ -463,6 +463,12 @@ class Command { $isWrite = array_key_exists( $fd, $readPipes ); if ( $isWrite ) { + // Don't bother writing if the buffer is empty + if ( $buffers[$fd] === '' ) { + fclose( $pipes[$fd] ); + unset( $pipes[$fd] ); + continue; + } $res = fwrite( $pipe, $buffers[$fd], 65536 ); } else { $res = fread( $pipe, 65536 ); diff --git a/tests/phpunit/includes/shell/CommandTest.php b/tests/phpunit/includes/shell/CommandTest.php index 3862cc24445..2e031638857 100644 --- a/tests/phpunit/includes/shell/CommandTest.php +++ b/tests/phpunit/includes/shell/CommandTest.php @@ -170,5 +170,12 @@ class CommandTest extends PHPUnit\Framework\TestCase { $command->input( str_repeat( '!', 1000000 ) ); $result = $command->execute(); $this->assertSame( 1000000, strlen( $result->getStdout() ) ); + + // And try it with empty input + $command = new Command(); + $command->params( 'cat' ); + $command->input( '' ); + $result = $command->execute(); + $this->assertSame( '', $result->getStdout() ); } }