title: Executing a .exe or .linux file in Java during Run time
body: <p>I am trying to create a function within a Java Class that can execute a .exe or a .linux file during runtime. 
  The program is espresso.exe (for Windows OS) and espresso.linux for (Linux based systems)</p>
  
  <p>Typically, the way to run the program is by going to command line, and going to the folder in which the executable is stored and typing:</p>
  
  <p>(in Command Prompt)</p>
  
  <p>espresso A0.txt > m.txt</p>
  
  <p>or espresso A0.txt (which returns the output in cmd)</p>
  
  <p>(in linux Terminal)</p>
  
  <p>./espresso.linux A0.txt > m.txt</p>
  
  <p>or ./espresso.linux A0.txt (which returns the output in the terminal window)</p>
  
  <p>Here A0.txt is the input argument and m.txt is the file that espresso creates. </p>
  
  <p>I have stored A0.txt and espresso.linux and espresso.exe under a folder src/resources</p>
  
  <p>I tried the following:</p>
  
  <pre><code> ProcessBuilder pb = new ProcessBuilder("./src/resources/espresso.exe","src/resources/A0.txt","&gt;src/resources/m.txt");
   try {
          Process p = pb.start();
   }catch (IOException ex) {
          Logger.getLogger(NetSynth.class.getName()).log(Level.SEVERE, null, ex);
   }
  </code></pre>
  
  <p>I also tried: </p>
  
  <pre><code>Runtime rt = Runtime.getRuntime();
  Process p = rt.exec("src/resources/espresso.linux src/resources/A0.txt &gt; src/resources/m.txt");
  int waitFor = p.waitFor();
  </code></pre>
  
  <p>Both of them fail to identify the file to be executed and do not run the command. I understand there may be many errors in the 2 approaches. I could use some help to figure out the approach and the code to be written to run the executable file. </p>
  
  <p>Also, is there a path to be mentioned to run espresso.linux? Will /src/resources/espresso.linux suffice?</p>
  
  <p>Thanks in advance. </p>