Bird
0
0

Which of the following is the correct way to invoke execFile with a callback to handle the output in Node.js?

easy📝 Syntax Q3 of 15
Node.js - Child Processes
Which of the following is the correct way to invoke execFile with a callback to handle the output in Node.js?
AexecFile('myProgram', ['arg1'], (error, stdout, stderr) => { /* handle output */ });
BexecFile('myProgram', (error, stdout) => { /* handle output */ });
CexecFile('myProgram', ['arg1'], (stdout, stderr) => { /* handle output */ });
DexecFile('myProgram', ['arg1'], error => { /* handle output */ });
Step-by-Step Solution
Solution:
  1. Step 1: Review execFile signature

    The correct signature is execFile(file, args, callback) where callback receives (error, stdout, stderr).
  2. Step 2: Analyze options

    execFile('myProgram', ['arg1'], (error, stdout, stderr) => { /* handle output */ }); correctly uses the callback with three parameters. execFile('myProgram', (error, stdout) => { /* handle output */ }); misses the args array. execFile('myProgram', ['arg1'], (stdout, stderr) => { /* handle output */ }); has wrong callback parameters order. execFile('myProgram', ['arg1'], error => { /* handle output */ }); only passes error.
  3. Final Answer:

    execFile('myProgram', ['arg1'], (error, stdout, stderr) => { /* handle output */ }); -> Option A
  4. Quick Check:

    Callback signature is (error, stdout, stderr) [OK]
Quick Trick: Callback receives error, stdout, stderr in that order [OK]
Common Mistakes:
  • Omitting the arguments array
  • Incorrect callback parameter order
  • Using only error parameter in callback

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes