Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

exec-sync

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

exec-sync - npm Package Compare versions

Comparing version 0.1.3 to 0.1.4

45

bin/index.js

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc