php – Interact with another programm in nodejs-ThrowExceptions

Exception or error:

Well, i have simple console programm (written in php), which outputs some information and then wait for user input and after input, again outputs some another information.

I need to write nodejs programm that will:

  1. Catch first output from this program
  2. Somehow saving this interaction in order to send command to it later.
  3. Process and show new text to user and wait for input (inside node)
  4. Grab user input and passes it to opened programm
  5. Show last output from php programm in node
  6. end nodejs

To keep it simple lets pretend the program is:

$line = readline("Enter your command: ");
print 'Thank you for submitting data.';

My main problem is that i don’t know how to handle “holding” php program opened.

What i ended up for now in node is this:

const readline = require('readline');
const exec = require('child_process').exec;
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout

exec('php programm.php', function(error, stdout, stderr){
  rl.question(stdout.toUpperCase(), (answer) => {

But that doesn’t work. Thanks in advance!

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *