title: How can I execute a Java command on nodeJS?
body: <p>I'm trying to compile a .java file with the javac command then I want to to execute it with the java command. Here is what I'm trying : </p>
  
  <pre><code>var spawn = require('child_process').spawn;
  var javac  = spawn('javac', [' C:/Users/Administator/Desktop/Hello.java']);
  var javaa  = spawn('java', [' C:/Users/Administator/Desktop/Hello']);
  
  javac.stdout.on('data', function out(data) {
      console.log(data);
      javaa.stdout.on('data', function out(data) {
          console.log(data);
      });
  
      javaa.stderr.on('data', function(data) {
          console.log("error");
      });
  
      javaa.on('exit', function out(data) {
          console.log(data);
      });
  });
  
  javac.stderr.on('data', function(data) {
      console.log("error");
  });
  
  javac.on('exit', function out(data) {
      console.log(data);
  });
  </code></pre>