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

shell-exec

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shell-exec

A tiny cross-platform promise based wrapper around child_process.spawn.

  • 1.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
214K
increased by7.06%
Maintainers
1
Weekly downloads
 
Created

What is shell-exec?

The shell-exec npm package allows you to execute shell commands from within a Node.js application. It provides a simple interface to run shell commands and capture their output, making it useful for tasks such as automation, scripting, and system administration.

What are shell-exec's main functionalities?

Execute Shell Commands

This feature allows you to execute shell commands and capture their output. In this example, the 'ls -la' command lists the contents of the current directory in long format, and the output is logged to the console.

const shell = require('shell-exec');
shell('ls -la').then(console.log).catch(console.error);

Handle Command Output

This feature allows you to handle the standard output (stdout) and standard error (stderr) of the executed command. In this example, the 'echo Hello, World!' command prints 'Hello, World!' to stdout, and the output is logged to the console.

const shell = require('shell-exec');
shell('echo Hello, World!').then(result => {
  console.log('stdout:', result.stdout);
  console.log('stderr:', result.stderr);
}).catch(console.error);

Error Handling

This feature allows you to handle errors that occur when executing a shell command. In this example, an invalid command is executed, and the error is caught and logged to the console.

const shell = require('shell-exec');
shell('invalidcommand').then(console.log).catch(error => {
  console.error('Command failed:', error);
});

Other packages similar to shell-exec

Keywords

FAQs

Package last updated on 17 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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