Nodejs encountered (Y or N) when running system commands. You must enter y or n to continue running downwards. The solution is What?

  node.js, question

Suppose the current nodejs is to run the commandrm -rf 123.txt, then the code is

process.exec('rm -rf 123.txx',function (error, stdout, stderr) {
 if (error !  == null) {
 Log ('execrerror:' plus error');
 }else {
 console.log(stdout)
 bracket
 });

OK, it has been deleted. But what if sudo is added? such assudo rm -rf 123.txt, you need to enter a password to delete. The following is what I tried, but it cannot be deleted:

process.exec('sudo rm -rf 123',function (error, stdout, stderr) {
 if (error !  == null) {
 Log ('execerror:' plus error');
 }else {
 Exec ('password', function (error, stdout, stderr) {
 if (error !  == null) {
 Log ('execerror:' plus error');
 }else {
 console.log(stdout)
 bracket
 });
 console.log(stdout)
 bracket
 });

This is what I tried to solve by nesting process.exec, but found that it could not be solved.

The above is an example. In actual projects, I need to use nodejs to call python or other scripts.
such asxxx.pyUnder the actual terminal, he is like this:

test@test:~/$ python xxx.py
 info:xxxxxxx
 Do you want to continue?  (Y or N):Y
 sys_info:xxxxx
 Do you want to quit?  (Y or N):N
 log_info:xxxxx
 test@test:~/$

If nodejs calls, what should I do and how should I get the prompt message to beDo you want to continue? (Y or N):When the automatic input Y, and press enter to continue down. When the prompt message isDo you want to quit? (Y or N):, automatically enter n, and then press enter to run.

sudoThere is an order-SOption, which is used to read the password when it needs to be entered.

Suppose the password is111111, then, the complete command is as follows

echo "111111" | sudo -S rm -rf ./123.txt

Correspondingly, the node code can look like this

var child_process = require('child_process');
 child_process.exec('echo "111111" | sudo -S rm -rf ./123.txt', function(error, stdout, stderr){
 if(error){
 throw error;
 }else{
 console.log(stdout);
 bracket
 });