Alvin Poh

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:

Share This With Others Who Would Find It Useful

Leave a Comment

Your email address will not be published. Required fields are marked *