Return output to parent in child_process

hi all, I'm writing a function with chil_process.exec and I would return a value to parent

var dir = flow.get("mntFolderName")

let checkOut
try {
      var mntCheckOutput = exec('mountpoint ' + dir, (error, stdout) => {
          if (error) {
              checkOut = false;
              return checkOutput;
          }
          if (!stdout.includes("is not a mountpoint")) {
              checkOut = true;
              return checkOutput;
          } else {
              checkOut = false;
              return checkOutput
          }
      });
      node.warn(mntCheckOutput)
  } catch (error) {
      checkOut = false;
      return
  }

the node.warn show me "[object object]"

How can i read true or false in the main project?

many thanks in advance

Hi @denissanga !

node.warn does what you told it to do; it tries to serialize mntCheckOutput to debug it to the log file.

exec yet runs async. To return checkOut, you may try to do something like:

    if (error) {
        checkOut = false;
        msg.payload = checkOut
        node.send(msg)
        node.done();
        return;
    }

Warn with an object or array...

node.warn({mntCheckOutput})

Or

node.warn(['mntCheckOutput',mntCheckOutput])

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.