Comparing version 0.1.3 to 0.1.4
@@ -0,3 +1,4 @@ | ||
// Generated by CoffeeScript 1.3.3 | ||
(function() { | ||
var FFI, fs, libc, tmpDir, uniqId, uniqIdK; | ||
var FFI, fs, getOutput, libc, tmpDir, uniqId, uniqIdK; | ||
@@ -36,17 +37,39 @@ FFI = require("ffi"); | ||
module.exports = function(cmd) { | ||
var dir, result, tmp; | ||
tmp = uniqId() + '.tmp'; | ||
getOutput = function(path) { | ||
var output; | ||
output = fs.readFileSync(path); | ||
fs.unlinkSync(path); | ||
output = "" + output; | ||
if (output.charAt(output.length - 1) === "\n") { | ||
output = output.substr(0, output.length - 1); | ||
} | ||
return output; | ||
}; | ||
module.exports = function(cmd, returnOutAndErr) { | ||
var dir, error, id, result, stderr, stdout; | ||
if (returnOutAndErr == null) { | ||
returnOutAndErr = false; | ||
} | ||
id = uniqId(); | ||
stdout = id + '.stdout'; | ||
stderr = id + '.stderr'; | ||
dir = tmpDir(); | ||
cmd = "" + cmd + " > " + dir + "/" + tmp; | ||
cmd = "" + cmd + " > " + dir + "/" + stdout + " 2> " + dir + "/" + stderr; | ||
libc.system(cmd); | ||
result = fs.readFileSync("" + dir + "/" + tmp); | ||
fs.unlinkSync("" + dir + "/" + tmp); | ||
result = "" + result; | ||
if (result.charAt(result.length - 1) === "\n") { | ||
result = result.substr(0, result.length - 1); | ||
result = getOutput("" + dir + "/" + stdout); | ||
error = getOutput("" + dir + "/" + stderr); | ||
if (returnOutAndErr) { | ||
return { | ||
stdout: result, | ||
stderr: error | ||
}; | ||
} else { | ||
if (error !== '') { | ||
throw new Error(error); | ||
} | ||
return result; | ||
} | ||
return result; | ||
}; | ||
}).call(this); |
{ | ||
"name": "exec-sync", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "Execute shell command synchronously. Use this for migration scripts, cli programs, but not for regular server code.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -28,5 +28,4 @@ # exec-sync | ||
### TODO | ||
By default, an Error is thrown if stderr is not empty. Alternatively, the function can return an object with both `stdout` and `stderr` as properties by passing `true` as a second argument (`returnOutAndErr`). | ||
Throw error when something went wrong. | ||
@@ -33,0 +32,0 @@ ## License |
Sorry, the diff of this file is not supported yet
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
7097
65
54
1