First thing is to fix that terrible catch clause.
If/when there is an error you just told Java that you didn't want to know anything about it, and please discard the detailed error message that Java just created for you.
ALWAYS put an e.printStackTrace(); in your catch blocks until/unless you … Read More
This really is the easiest way... for example here's all the code to run a ls (list directory contents) command and display the output and any errors.
ProcessBuilder pb = new ProcessBuilder("ls");
(plus 4 lines if you wrap that in a try/catch/printStackTrace())
You don't need all that … Read More
Yes, I did come on strong about obsolete versions of Java, but I'm not going to apologise. There really are hideous exploits for older versions of Java in the wild, and if you don't replace them with a currently-supported version you are definitely at risk.
A clean download/install of … Read More
Go to http://www.oracle.com/technetwork/java/javase/downloads/jdk-netbeans-jsp-142931.html and download the JDK/NetBeans bundle for Mac OSX. That's everything you need in one package.
It's a standard Mac disk image installer, coudn't be simpler.
When you get your code running with all the errors displayed you will find that the ~ is a problem. Come back … Read More
Scroll down to near the bottom for the start() function.
> public Process start()
> throws IOException
Look at your error...
> Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - unreported exception java.io.IOException; must be caught or declared to be thrown
You aren't catching the IOException in your … Read More
Seriously - you commented out line 13? Are we wasting our time here? Read More
You always need to split up the command and it parameters. Don't use special-case code like that, you should split up every command, ie
new ProcessBuilder(cmd.split(" "));
In summary, the easiest general way to execute a command under OSX from Java is to use something like: (also deals with ~ … Read More