3
I’m trying to make a script on Node.js to update my computer.
I’m using child_process.spawn
.
When typing sudo apt update
, it keeps waiting for the password. I have tried to inform with stdin.write
, but I was unsuccessful.
PS: It has to be with sudo.
var spawn = require('child_process').spawn;
app.post('/update',cors(), function (req, res) {
let command = `sudo apt udpate'`
const cmd = spawn(command,[], { shell: true });
cmd.stdin.write("minhasenha\n");
cmd.stdout.on('data', (data) => {
// cmd.stdin.write("minhasenha");
console.log(`stdout: ${data}`);
});
})