Complete the code to import the exec function from the child_process module.
const { [1] } = require('child_process');The exec function is imported from the child_process module to run shell commands.
Complete the code to run the shell command 'ls -l' using exec.
exec('[1]', (error, stdout, stderr) => { if (error) { console.error(`Error: ${error.message}`); return; } console.log(stdout); });
The command ls -l lists files in long format on Unix-like systems.
Fix the error in the callback parameters to correctly handle exec output.
exec('node -v', ([1]) => { if (error) { console.error(error); return; } console.log(stdout); });
The callback for exec receives three parameters: error, stdout, and stderr.
Fill both blanks to run 'echo Hello' and print the output or error.
exec('[1]', (error, [2], stderr) => { if (error) { console.error(`Error: ${error.message}`); return; } console.log([2]); });
The command is echo Hello and the output is in stdout.
Fill all three blanks to run 'cat file.txt', handle errors, and print output.
exec('[1]', ([2], [3], stderr) => { if ([2]) { console.error(`Error: $[2].message}`); return; } console.log([3]); });
The command cat file.txt reads the file content. The callback parameters are error and stdout for output.
