Skip to content

Instantly share code, notes, and snippets.

@shubham-sharmas
Created October 30, 2023 15:12
Show Gist options
  • Save shubham-sharmas/625a635320281a0ce14c4d829691fe2b to your computer and use it in GitHub Desktop.
Save shubham-sharmas/625a635320281a0ce14c4d829691fe2b to your computer and use it in GitHub Desktop.
Node.js child_process.exec() method example
const { exec } = require('child_process');
exec('ls -l -a', { cwd: process.env.HOME }, (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
if (stderr) {
console.error(`stderr: ${stderr}`);
} else {
console.log(`stdout: ${stdout}`);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment