/** * launch the given interactive $command shell * * Its STDOUT will be used to parse responses, the STDIN will be used * to pass commands. * * If the command prints output to STDERR, make sure to redirect it to * STDOUT by appending " 2>&1". * * @param string|Process $process accepts either a command string to execute or a Process instance * @return DeferredShell */ public function createDeferredShell($process) { if (!$process instanceof Process) { $process = new Process($process); } $process->start($this->loop); $stream = new CompositeStream($process->stdout, $process->stdin); // forcefully terminate process when stream closes $stream->on('close', function () use($process) { if ($process->isRunning()) { $process->terminate(SIGKILL); } }); return new DeferredShell($stream); }
public function __construct(DNode $dnode, Session $client, $onReady) { $this->dnode = $dnode; foreach ($this->dnode->stack as $middleware) { call_user_func($middleware, array($client->instance, $client->remote, $client)); } if ($onReady) { $client->on('ready', function () use($client, $onReady) { call_user_func($onReady, $client->remote, $client); }); } $input = new InputStream($client); $output = new OutputStream($client); parent::__construct($output, $input); }
/** @test */ public function itShouldForwardPipeCallsToReadableStream() { $readable = new ReadableStream(); $writable = $this->getMock('React\\Stream\\WritableStreamInterface'); $composite = new CompositeStream($readable, $writable); $output = $this->getMock('React\\Stream\\WritableStreamInterface'); $output->expects($this->once())->method('write')->with('foo'); $composite->pipe($output); $readable->emit('data', array('foo')); }