Skip to content

Instantly share code, notes, and snippets.

@shubham-sharmas
Last active October 30, 2023 19:00
Show Gist options
  • Save shubham-sharmas/276df434d55af5f2d6ad1cfa7f00be02 to your computer and use it in GitHub Desktop.
Save shubham-sharmas/276df434d55af5f2d6ad1cfa7f00be02 to your computer and use it in GitHub Desktop.
Node.js child_process.spawn() method example
const { spawn } = require('child_process');
const shellProcess = spawn('ls', ['-l', '-a']);
shellProcess.stdout.on('data', (data) => {
console.log(`Shell Output: ${data}`);
});
shellProcess.stderr.on('data', (data) => {
console.log(`Shell Error: ${data}`);
});
shellProcess.on('close', (code) => {
console.log(`Shell process exited with code ${code}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment