Last active
October 30, 2023 19:00
-
-
Save shubham-sharmas/276df434d55af5f2d6ad1cfa7f00be02 to your computer and use it in GitHub Desktop.
Node.js child_process.spawn() method example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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