title: NodeJS respond to a shell prompt
body: <p>I launch a shell script from a NodeJS app.<br>
  At a certain point, the shell script ask for a user input ( a Y/N confirmation ).<br>
  The node app is running on a RaspberryPi and the confirmation is done by a physical button (no keyboard) so the "prompt answer" has to be done by code.<br>
  I tried :</p>
  
  <pre><code>childProcess.stdin.write("y\n");
  childProcess.stdin.end();
  </code></pre>
  
  <p>but nothing happens.<br>
  Just to be clear, I've tested entering the "y" manually on the console and it works, the script continues its course</p>
  
  <p>Here's my simplyfied code:</p>
  
  <p>node app:</p>
  
  <pre><code>var Gpio = require('pigpio').Gpio;
  class Main {
    constructor() {
      this.prompt = false;
      const button = new Gpio(17, {
        mode: Gpio.INPUT,
        pullUpDown: Gpio.PUD_DOWN,
        edge: Gpio.EITHER_EDGE
      });
      button.on('interrupt', (level) =&gt; {
        if (level == 1) {
          this.onButtonPress();
        } else if (level == 0) {
          this.onButtonRelease();
        }
      });
      this.childProcess = require('child_process').spawn('sudo', ['miLazyCracker']);
      this.childProcess.stdout.on('data', (dataBuffer) =&gt; {
        var data = dataBuffer.toString();
        console.log(data);
        if (data.includes("Do you want clone the card?")) {
          this.prompt = true;
        }
      });
    }
    onButtonPress() {
  
    }
    onButtonRelease() {
      if (this.prompt) {
        this.childProcess.stdin.write("y\n");
        this.childProcess.stdin.end();
        console.log("sent prompt confirmation");
      }
    }
  }
  new Main();
  module.exports = Main;
  </code></pre>
  
  <p>The shell script : <a href="https://github.com/nfc-tools/miLazyCracker/blob/master/miLazyCracker.sh" rel="nofollow noreferrer">https://github.com/nfc-tools/miLazyCracker/blob/master/miLazyCracker.sh</a></p>
  
  <p>Here is the simplyfied console output:</p>
  
  <pre><code>[Useless start of the script]
  
  Do you want clone the card? Place card on reader now and press Y [y/n]
  sent prompt confirmation
  </code></pre>