-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexeccommand.js
38 lines (34 loc) · 952 Bytes
/
execcommand.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
36
37
38
var execSync;
//Seeing whether the required dependencies are installed
try {
execSync = require("execsync");
}
catch (exception) {
//Setting to null, to stop further execution
execSync = null;
}
// Executing the code in the statement below if the dependencies are found
if (execSync !== null)
{
module.exports = function(command) {
// Using execsync module as an exception, until child_process.execSync()
// arrives in node v0.12.x
var result;
try {
result = execSync(command);
var end = result.lastIndexOf("\n"); // Removing last nextline character
if (end > 0 && end !== null) { // Null check for result content that is null
result = result.slice(0, end);
}
return result;
}
catch (exception) {
console.error(exception);
return exception;
}
};
}
else {
console.log("The required dependencies are not installed!");
console.log("execsync: %s", execSync !== null ? "Installed" : "NOT INSTALLED");
}