title: Saving the output of a child process in a variable in the parent in NodeJS
body: <p>I would like to start a child process in NodeJS and save it's output into a variable. The following code gives it to stdout:</p>
  
  <pre><code>require("child_process").execSync("echo Hello World", {"stdio": "inherit"});
  </code></pre>
  
  <p>I have something in mind that is similar to this code:</p>
  
  <pre><code>var test;
  require("child_process").execSync("echo Hello World", {"stdio": "test"});
  console.log(test);
  </code></pre>
  
  <p>The value of <code>test</code> was supposed to be <code>Hello World</code>.</p>
  
  <p>Which does not work, since <code>"test"</code> is not a valid stdio value. </p>
  
  <p>Perhaps this is possible using environment variables, however I did not find out how to modify them in the child process with the result still being visible to the parent.</p>