Running UNIX commands in your Java application

I was looking around for a method to run commands from the prompt automatically from within my Java application, and then I found it. Here’s the solution – and it works like a charm!

static void doExec1() throws IOException {

// use pipes and I/O redirection
// but without using a shell

Runtime runtime = Runtime.getRuntime();
runtime.exec(“ls | wc >out1”);

Similar Posts:

Alvin Poh lives in Singapore, and is interested in marketing, techy stuff, and likes to just figure out how the two can work with each other. He can also be found on Google+.

Leave a reply:

Your email address will not be published.


Sliding Sidebar