1

I have a bidirectional stream $stream returned from ssh2_exec($command). The stream represents both the input and output of the command.

I can send input to the command with fwrite($stream) and I can read the command's output with fread($stream).

I can check for the end of output with feof($stream), but I have no way to tell the command about the end of input.

If I call fclose($stream), the bidirectional stream is destroyed completely, and any following fread($stream) fails.

How can I do something like fcloseinput($stream) to close just the input part of the bidirectional stream?

Jesse
  • 6,725
  • 5
  • 40
  • 45
  • Perhaps `fflush`, or writing EOT or some other control character? – Waleed Khan Nov 11 '13 at 03:30
  • My test case is the command `cat`. I've tried `fwrite( $stream, $data ); fflush( $stream );` and `fwrite( $stream, $data . "\x4" );` (\x4 being EOT) neither of which cause `cat` to stop waiting for input. – Jesse Nov 11 '13 at 03:35
  • How about other control characters? You could loop through them all, and if one works, you just have to narrow it down. – Waleed Khan Nov 11 '13 at 03:36
  • I've tried every control character (ordinals 0 to 64) and none of them cause `cat` to stop reading input. – Jesse Nov 11 '13 at 03:39
  • As a workaround, perhaps you could write to a temporary file on the remote server and just pipe that into the command you want? – Waleed Khan Nov 11 '13 at 03:46
  • I would like to avoid that. – Jesse Nov 11 '13 at 03:49

0 Answers0