Sudo Command Node Webkit
1 answer
With nodejs, you can execute commands in a shell with a child process and an exec function. Here is the documentation: http://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback
Example:
var exec = require('child_process').exec;
var child;
child = exec('sudo chown -R username:group /home/myuser/myfolder',
function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});
Now you have stdout, stdint, which are streams, and you can write your password by writing it to the stream like this:
child.stdin.write("mypassword");
You can also check out this module for using sudo commands: https://www.npmjs.org/package/sudo
0
source to share