title: Running Bash Script in Java
body: <p>So essentially, I am trying to run the command "/dir/command -arg" to change the LED color on a USB device in Java. I am using Ubuntu 10.04. When I run the command from the terminal, it works just fine.</p>
  
  <p>However, I tried every iteration of Runtime.exec() that I could find and none of them seem to work. I then created a script with the following contents:</p>
  
  <pre><code>#!/bin/bash
  echo "hello"
  /dir/command -arg
  </code></pre>
  
  <p>when I run this from a terminal it works just fine. However when I run </p>
  
  <pre><code>@Override
  public void run() {
      String[] lookupCmd = {"/bin/sh","-c", "sh /dir/script.sh"};
      try {
        Runtime runtime = Runtime.getRuntime();
        Process lookupProc = runtime.exec(lookupCmd);
        lookupProc.waitFor();
        BufferedReader reader = new BufferedReader(new InputStreamReader(lookupProc.getInputStream()));
        String line = reader.readLine();        
        while (line != null) {
          id.add(line);
          System.out.println(line);
          line = reader.readLine();
        }
      } catch (Exception e) {
        System.err.println(e);
      }
    }
  </code></pre>
  
  <p>"hello" print but nothing else. There is no error.</p>
  
  <p>My other command should not yield any output, but simply change the color of an LED. However when I run it with the same command but a different arg which yields an ouput, it still only prints "hello".</p>
  
  <p>I also made sure that my user has permissions to the /dev folder with the usb device.</p>