Goal
I want to show graphical password prompt in nodejs to elevate priviledge thus gain some power to copy file content into another, but the last is owned by root.
In the implementation, I try to execute dd along with it's argument with gksudo with exec() function.
exec = require('child_process').exec
printall = function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error) {
console.log('exec err: ' + error);
}
}
exec("gksudo dd if=/home/user/minor.txt of=/home/user/major.txt", printall)
Error
But I always fail, with no good reason.
It said,
stdout:
stderr:
exec err: Error: Command failed: /bin/sh -c gksudo dd if=/home/user/minor.txt of=/home/user/major.txt
If I reproduce the command into terminal, it missed double quotes and instead run gksudo only. Well, in nodejs, it simply fails.
Notes
I originally develop Atom package. It's my first time, so, I found out about a different version of Node (or IOJs?). I execute the whole code inside Atom.
Question
If you expect a clear question, well, possibly
How to execute
gksudowithin node.js to run other command along with the arguments?