Run bash scripts from JAVA and return the results
<p>I am attempting to get output of a shell / bash script, that is run from a JAVA program, although I am not having much luck, the code is as follows:</p>

<pre><code>GetStats(winhostname);

public static String winhostname "cmd /c hostname";

public static void GetStats(String operation)
    {
         try 
            { 
            Process p=Runtime.getRuntime().exec(operation); 
            p.waitFor(); 
            BufferedReader reader=new BufferedReader(new InputStreamReader(p.getInputStream())); 
            String line=reader.readLine(); 
            while(line!=null) 
            { 
            System.out.println(line);
            if (operation.equals("winhostname"))
            {
                winhostnamevalue = line;
            }
            line=reader.readLine(); 
            } 

            } 
            catch(IOException e1) {} 
            catch(InterruptedException e2) {}       
    }
</code></pre>

<p>This works on Windows fine, so I changed the value of winhostname to "sh namecheck.sh" (which simply echos the hostname) and the shell script is located in the same directory as the java / class file. Although when run I get a blank result, not null, just blank.</p>
