Skip to content

Instantly share code, notes, and snippets.

@soyuka
Created October 14, 2014 14:22
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 soyuka/9d5f38761e831d20d99b to your computer and use it in GitHub Desktop.
Save soyuka/9d5f38761e831d20d99b to your computer and use it in GitHub Desktop.
Node to php stdin test
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')]
})
<?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