I’m using this code to make my Java program open a (visible) CMD window:
try { String line; Process p = Runtime.getRuntime().exec('cmd /C start \'Render\' \'' + myPath + '\\punchRender.cmd\''); BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); while ((line = input.readLine()) != null) { System.out.println(line); jLabel7.setText(line); } input.close(); } catch (Exception err) { err.printStackTrace(); }
and I’ve been trying to do the same thing with the OSX terminal, this is where I’m at right now:
try { String line; Process p = Runtime.getRuntime().exec('sh ' + myPath + '/punchRender.sh'); BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); while ((line = input.readLine()) != null) { System.out.println(line); jLabel7.setText(line); } input.close(); } catch (Exception err) { err.printStackTrace(); }
So far, no luck 🙁 Any suggestions? The .sh file isn’t even running…
I would just make sure your shell script has the execute bits on and just pass in the shell script file name.
Process p = Runtime.getRuntime().exec(myPath + '/punchRender.sh')Edit:
I don’t know Java specifically if there is anyway to set file permissions for Unix/Linux with it to set the eXecute bit or how to escape quotes. But It would be something like this:
Process chmod = Runtime.getRuntime().exec('chmod u+x \'' + myPath + '/punchRenderer.sh\'')