If the write buffer for a file descriptor is empty, don't try to write
to it. Just close it and continue on.
Bug: T188019
Change-Id: Ie5b5ac1ef1aec4ae763cf4d0d58d3a28e42b7d2a
$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 );
$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() );
}
}