forked from jorangreef/sudo-prompt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-spawn.js
35 lines (30 loc) · 848 Bytes
/
test-spawn.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
var assert = require("assert");
var fs = require("fs");
var sudo = require("./");
var exec = require("child_process").exec;
function kill(end) {
if (process.platform === "win32") return end();
exec("sudo -k", end);
}
function icns() {
if (process.platform !== "darwin") return undefined;
var path = "/Applications/Electron.app/Contents/Resources/Electron.icns";
try {
fs.statSync(path);
return path;
} catch (error) {}
return undefined;
}
kill(function () {
var options = {
env: { SUDO_PROMPT_TEST_ENV: "hello world" },
icns: icns(),
name: "Electron",
//spawn: { detached: true, stdio: ["ignore"] },
spawn: { detached: true, stdio: ["ignore"], keepOpen: true },
};
var command = "echo test";
sudo.spawn(command, options, function (response) {
console.log("response:", response);
});
});