Created
April 1, 2019 07:48
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while (my $line = <STDIN>) { | |
print $line; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment