Last active
July 26, 2021 11:42
-
-
Save killshot13/be2558cfc43a77248d6838493b03b77a to your computer and use it in GitHub Desktop.
nodeFunctions();
This file contains hidden or 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 { 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) | |
}); |
This file contains hidden or 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 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