Skip to content

Instantly share code, notes, and snippets.

@Naktibalda
Created April 1, 2019 07:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Naktibalda/a63015d90d201389941e7353e929294b to your computer and use it in GitHub Desktop.
Save Naktibalda/a63015d90d201389941e7353e929294b to your computer and use it in GitHub Desktop.
Perl script reads line from stdin, writes response to stdout. It doesn't work when executed from php
<?php
$descriptors = [
0 => ["pipe", "r"], // stdin is a pipe that the child will read from
1 => ["pipe", "w"], // stdout is a pipe that the child will write to
2 => ["pipe", "w"], // stderr is a file to write to
];
$pipes = [];
$command = 'perl test.pl';
$process = proc_open($command, $descriptors, $pipes);
echo "writing to stdin\n";
fputs($pipes[0], "test\r\n");
echo "reading from stdout\n";
echo fgets($pipes[1]);
echo "done\n";
while (my $line = <STDIN>) {
print $line;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment