Skip to content

Instantly share code, notes, and snippets.

@sintaxi
Created September 2, 2013 20:29
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sintaxi/6416999 to your computer and use it in GitHub Desktop.
Save sintaxi/6416999 to your computer and use it in GitHub Desktop.
trying to spawn a child process as root user without being prompted in main script.
// test by running `node test.js`
var spawn = require("child_process").spawn
var child = spawn("sudo", [__dirname + "/bin/server"])
child.stderr.on('data', function (data) {
child.stdin.write("somepassword" + '\n');
})
@nikita-fuchs
Copy link

Unfortunately, this doesn't work anymore (Mac Catalina) :/

@terryops
Copy link

Unfortunately, this doesn't work anymore (Mac Catalina) :/

Tried on Big Sur, still working.

@aylusltd
Copy link

Did not work on Monterey (12.0.1). I added the "-S" flag to the beginning of the args array and that fixed it. const child = spawn("sudo", ["-S","-k","echo","Hello"]) Per this man page

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment