Socket
Socket
Sign inDemoInstall

exec-sh

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

exec-sh - npm Package Compare versions

Comparing version 0.2.1 to 0.2.2

test/exec-sh.js

23

example/example.js

@@ -1,18 +0,17 @@

var execSh = require("../");
var execSh = require('../')
// run interactive bash shell
execSh("echo ola && bash", { cwd: "/home" }, function(err){
execSh('echo ola && bash', { cwd: '/home' }, function (err) {
if (err) {
console.log("Exit code: ", err.code);
return;
console.log('Exit code: ', err.code)
return
}
// collect streams output
var child = execSh(["bash -c id", "echo olaola >&2"], true,
function(err, stdout, stderr){
console.log("error: ", err);
console.log("stdout: ", stdout);
console.log("stderr: ", stderr);
});
});
execSh(['bash -c id', 'echo olaola >&2'], true,
function (err, stdout, stderr) {
console.log('error: ', err)
console.log('stdout: ', stdout)
console.log('stderr: ', stderr)
})
})

@@ -1,8 +0,5 @@

var
cp = require("child_process"),
merge = require("merge");
var cp = require('child_process')
var merge = require('merge')
var
sh, cmd,
defSpawnOptions = { stdio: "inherit" };
var defSpawnOptions = { stdio: 'inherit' }

@@ -14,7 +11,7 @@ /**

*/
function getShell(){
if (process.platform === "win32") {
return { cmd: "cmd", arg: "/C" };
function getShell () {
if (process.platform === 'win32') {
return { cmd: 'cmd', arg: '/C' }
} else {
return { cmd: "sh", arg: "-c" };
return { cmd: 'sh', arg: '-c' }
}

@@ -34,58 +31,57 @@ }

*/
function execSh(command, options, callback){
function execSh (command, options, callback) {
if (Array.isArray(command)) {
command = command.join(";");
command = command.join(';')
}
if (options === true) {
options = { stdio: null };
options = { stdio: null }
}
if (typeof options === "function") {
callback = options;
options = defSpawnOptions;
if (typeof options === 'function') {
callback = options
options = defSpawnOptions
} else {
options = options || {};
options = merge(true, defSpawnOptions, options);
callback = callback || function(){};
options = options || {}
options = merge(true, defSpawnOptions, options)
callback = callback || function () {}
}
var
child,
stdout = "", stderr = "",
shell = getShell();
var child
var stdout = ''
var stderr = ''
var shell = getShell()
try {
child = cp.spawn(shell.cmd, [shell.arg, command], options);
child = cp.spawn(shell.cmd, [shell.arg, command], options)
} catch (e) {
callback(e, stdout, stderr);
return;
callback(e, stdout, stderr)
return
}
if (child.stdout) {
child.stdout.on("data", function(data){
stdout += data;
});
child.stdout.on('data', function (data) {
stdout += data
})
}
if (child.stderr) {
child.stderr.on("data", function(data){
stderr += data;
});
child.stderr.on('data', function (data) {
stderr += data
})
}
child.on("close", function(code){
child.on('close', function (code) {
if (code) {
var e = new Error("Shell command exit with non zero code: " + code);
e.code = code;
callback(e, stdout, stderr);
var e = new Error('Shell command exit with non zero code: ' + code)
e.code = code
callback(e, stdout, stderr)
} else {
callback(null, stdout, stderr);
callback(null, stdout, stderr)
}
});
})
return child;
return child
}
module.exports = execSh;
module.exports = execSh
{
"name": "exec-sh",
"version": "0.2.1",
"version": "0.2.2",
"description": "Execute shell command forwarding all stdio.",
"main": "lib/exec-sh.js",
"scripts": {
"test": "npm run cover-test && npm run jshint",
"test": "npm run lint && npm run cover-test",
"cover-test": "istanbul cover --dir artifacts/coverage _mocha -- --reporter spec",
"jshint": "jshint lib/ example/ test/ package.json",
"lint": "standard --verbose **/*.js",
"dev": "mocha --reporter spec --watch",

@@ -35,12 +35,13 @@ "jsdoc": "jsdoc --private --destination artifacts/jsdoc lib/"

"dependencies": {
"merge": "^1.1.3"
"merge": "^1.2.0"
},
"devDependencies": {
"coveralls": "^2.11.2",
"istanbul": "^0.3.2",
"jsdoc": "^3.3.0-alpha8",
"jshint": "^2.5.1",
"mocha": "^1.20.1",
"sinon": "^1.10.2"
"coveralls": "^3.0.1",
"istanbul": "^0.4.5",
"jsdoc": "^3.5.5",
"jshint": "^2.9.5",
"mocha": "^5.2.0",
"sinon": "^6.0.1",
"standard": "^11.0.1"
}
}

@@ -5,2 +5,3 @@ # exec-sh

[![NPM Downloads](https://img.shields.io/npm/dm/exec-sh.svg)](https://www.npmjs.com/package/exec-sh)
[![Build Status](https://travis-ci.org/tsertkov/exec-sh.svg?branch=master)](https://travis-ci.org/tsertkov/exec-sh)

@@ -7,0 +8,0 @@ [![Coverage Status](https://img.shields.io/coveralls/tsertkov/exec-sh.svg)](https://coveralls.io/r/tsertkov/exec-sh?branch=master)

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