title: Running MATLAB function from Java
body: <p>I have an .m file in MATLAB which I would like to call from Java an get the solution as a string or whatever in Java. This sounds really simple but for some reason I can't make it work.</p>
  
  <p>I tried this:</p>
  
  <pre><code>matlab -nosplash -wait -nodesktop -r  myFunction
  </code></pre>
  
  <p>but I'm not sure how I parse the answer since MATLAB opens it's own command line (in Windows).</p>
  
  <p>I use this, but it doesn't return anything.</p>
  
  <pre><code>Process p = Runtime.getRuntime().exec(commandToRun);
  BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
  </code></pre>
  
  <p>also it seems that every time I call MATLAB it opens a separate window which is a problem because I'd like to run this many times.</p>