Created
October 14, 2014 14:22
-
-
Save soyuka/9d5f38761e831d20d99b to your computer and use it in GitHub Desktop.
Node to php stdin test
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
var fs = require('fs'); var spawn = require('child_process').spawn; | |
//dummy stdin file | |
var stdin = fs.openSync('stdin_file', 'w+'); | |
//write the string | |
fs.writeSync(stdin, 'test'); | |
spawn('php', ['stdin_test.php'], { | |
cwd: __dirname, | |
detached: true, | |
//to fully detach the process nothing should be piped from or to the parent process | |
stdio: [stdin, fs.openSync('out.log', 'a'), fs.openSync('err.log', 'a')] | |
}) |
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 | |
error_log('php://stdin'); | |
//this should log 'test' but outputs a newline | |
error_log(trim(fgets(STDIN))); | |
$t = fopen('/dev/stdin', 'r'); | |
error_log('/dev/stdin:'); | |
//this is working | |
error_log(trim(fgets($t))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Related stackoverflow question - Trying to understand the difference between /dev/stdin and php://stdin.