Java tutorial
//package com.java2s; import java.io.BufferedWriter; import java.io.OutputStreamWriter; public class Main { public static Process execute(String command) throws Exception { final Process process = new ProcessBuilder("sh").redirectErrorStream(true).start(); BufferedWriter stdOutput = new BufferedWriter(new OutputStreamWriter(process.getOutputStream())); stdOutput.write(command + "; exit\n"); stdOutput.flush(); stdOutput.close(); return process; } }