Socket
Socket
Sign inDemoInstall

spawn-sync

Package Overview
Dependencies
Maintainers
3
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

spawn-sync

Prollyfill for child_process.spawnSync


Version published
Weekly downloads
815K
increased by2.21%
Maintainers
3
Weekly downloads
 
Created

What is spawn-sync?

The spawn-sync npm package provides synchronous versions of Node.js's child_process.spawn and child_process.spawnSync functions. It allows you to execute shell commands and scripts synchronously, which can be useful in scenarios where you need to ensure that a command has completed before proceeding with the next step in your code.

What are spawn-sync's main functionalities?

Synchronous Command Execution

This feature allows you to execute shell commands synchronously. In this example, the 'ls -lh /usr' command is executed, and the output is printed to the console.

const spawnSync = require('spawn-sync');
const result = spawnSync('ls', ['-lh', '/usr']);
console.log(result.stdout.toString());

Handling Command Output

This feature allows you to handle the output of the executed command. In this example, the 'node -v' command is executed to get the Node.js version, and the output is printed to the console. If there's an error, it is logged to the console.

const spawnSync = require('spawn-sync');
const result = spawnSync('node', ['-v']);
if (result.error) {
  console.error('Error:', result.error);
} else {
  console.log('Node version:', result.stdout.toString());
}

Passing Environment Variables

This feature allows you to pass custom environment variables to the executed command. In this example, the 'printenv' command is executed with a custom environment variable 'CUSTOM_VAR' set to 'HelloWorld'. The output is printed to the console.

const spawnSync = require('spawn-sync');
const result = spawnSync('printenv', [], { env: { ...process.env, CUSTOM_VAR: 'HelloWorld' } });
console.log(result.stdout.toString());

Other packages similar to spawn-sync

FAQs

Package last updated on 16 Jul 2015

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