Skip to content

Instantly share code, notes, and snippets.

@killshot13
Last active July 26, 2021 11:42
Show Gist options
  • Save killshot13/be2558cfc43a77248d6838493b03b77a to your computer and use it in GitHub Desktop.
Save killshot13/be2558cfc43a77248d6838493b03b77a to your computer and use it in GitHub Desktop.
nodeFunctions();
const { exec } = require('child_process')
exec('ls -ltra', (error, stdout, stderr) => {
if(error) {
// if an error occurs during exec process
console.error("Error", error.message);
return;
} else if(stderr) {
// if exec ran but and error was generated
console.error("Stderr", stderr)
} else {
// if exec ran successfully
console.log("Output : ", stdout)
});
const { spawn } = require('child_process')
const ls = spawn("ls" , ["-ltra", "."])
ls.stdout.on("data" , data => {
console.log(`stdout , ${data}`)
})
ls.stderr.on("data" , data => {
console.log(`stderr ${data}`)
})
ls.on("error", error => {
console.error(`error, ${error.message}`)
})
ls.on("close", code => {
console.log(`Process exited with code , ${code}`)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment