title: Running a bash shell script in java
body: <p>I want to run a shell script from my program below but it doesn't seem to do anything. I've run the same command directly in the linux terminal and it works fine so I'm guessing it's my java code. As you can see, I was first writing the command to the shell script using a PrintWriter but I expect that this would not effect the running of the shell script itself. Any help would be appreciated!</p>
  
  <pre><code>    public static void main(String[] args) {
      // TODO Auto-generated method stub
  
      String nfdump = "nfdump -o csv -r /home/shane/Documents/nfdump/nfcapd.201211211526&gt;blank.txt";
  
      try {
          FileWriter fw = new FileWriter("/home/shane/Documents/script.sh");
  
          PrintWriter pw = new PrintWriter(fw);
  
          pw.println("#!/bin/bash");
          pw.println(nfdump);
  
          pw.close();
      } catch (IOException e1) {
          // TODO Auto-generated catch block
          e1.printStackTrace();
      }
  
      Process proc = null;
  
      try {
          proc = Runtime.getRuntime().exec("sh /home/shane/Documents/script.sh");
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  </code></pre>