title: Node.js: Process Spawn Hang
body: <p>I am trying to run the following shell command:</p>
  
  <p><code>netstat -nat | grep 3000</code></p>
  
  <p>and eventually</p>
  
  <p><code>netstat -nat | grep 3000 | grep ESTABLISHED</code></p>
  
  <p>from Node.js to obtain ip address connected to specific port using <code>spawn</code> according to <a href="https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options" rel="nofollow noreferrer">https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options</a> visible below:</p>
  
  <pre><code>const netStat = spawn('netstat', ['-nat']);
  const grep = spawn('grep', ['3000']);
  
  netStat.stdout.on('data', (data) =&gt; {
    grep.stdin.write(data);
  });
  
  console.log('Determining public ip\'s connected to port 3000');
  grep.stdout.on('data', function(data){
    console.log(data.toString());
  });
  </code></pre>
  
  <p>But the result just hangs, am I doing something wrong?
  Thanks in advance for the help!</p>