Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. const cp = require("child_process");
  2. const cmd = cp.spawn("sudo", ["-S", "ls", "-lh", "/usr"]);
  3.  
  4. cmd.stdout.on("data", data => {
  5. console.log(`stdout: ${data}`);
  6. });
  7.  
  8. cmd.stderr.on("data", data => {
  9. console.log(`stderr: ${data}`);
  10. if (String(data).match(/Password:/i)) {
  11. cmd.stdin.write(SUDO_PASSWORD + "\n");
  12. }
  13. });
  14.  
  15. cmd.on("close", code => {
  16. console.log(`child process exited with code ${code}`);
  17. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement