title: How to get the output of shell script into a variable in nodejs?
body: <p>I am trying to run a shell script inside my node js application and store the output of the shell script into a variable. I have the following code:</p>
  
  <pre><code>let run_number = parseInt(supervisor_row["producerState"].rows[0]["Run Number"]);
  const exec = require('child_process').exec;
  var yourscript = exec('sh run.sh run_number',
      (error, stdout, stderr) =&gt; {
          console.log(`${stdout}`);
          console.log(`${stderr}`);
          if (error !== null) {
              console.log(`exec error: ${error}`);
          }
      });
  </code></pre>
  
  <p>As you can see first I am getting the run_number in the first line. Next, I am trying to run the shell script inside a child_process. I am passing the run_number as an input to the shell script. The shell script returns a string. I want to store the output of the shell script inside a variable. Can I do it simply by let somestr = ${stdout};. Please help.   </p>