Skip to content

child_process.exec()'s stdout in outerscope #1303

@atombug

Description

@atombug
  • Version: 10.2.1
  • Platform: Windows 10 64-bit
  • Subsystem: child_process.exec()

Scenario:
I was creating a nodejs library now that is nearly complete i just want to export it but problem is how to access stdout of exec() outside of it's scope.

  • Code:
let data = "";
const { exec } = require('child_process');
exec('echo test', (error, stdout, stderr) => {
  if (error) {
    console.error(`exec error: ${error}`);
    return;
  }
  data = stdout;
  console.log(`stdout: ${stdout}`);
});
console.log(data);
  • OUTPUT:
stdout: test

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions