1const { exec } = require("child_process");
2exec("cat index.js", (error, data, getter) => {
3 if(error){
4 console.log("error",error.message);
5 return;
6 }
7 if(getter){
8 console.log("data",data);
9 return;
10 }
11 console.log("data",data);
12
13});
14
1// You can use 'exec' this way
2// LINUX EXAMPLE
3
4const { exec } = require("child_process");
5
6exec("ls -la", (error, stdout, stderr) => {
7 if (error) {
8 console.log(`error: ${error.message}`);
9 return;
10 }
11 if (stderr) {
12 console.log(`stderr: ${stderr}`);
13 return;
14 }
15 console.log(`stdout: ${stdout}`);
16});
1const { exec } = require('child_process');
2exec('ls | grep js', (err, stdout, stderr) => {
3 if (err) {
4 //some err occurred
5 console.error(err)
6 } else {
7 // the *entire* stdout and stderr (buffered)
8 console.log(`stdout: ${stdout}`);
9 console.log(`stderr: ${stderr}`);
10 }
11});