Java tutorial
import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { public static void main(String argv[]) throws Exception { String line; Process p = Runtime.getRuntime().exec("psql -U username -d dbname -h serverhost -f scripfile.sql"); BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); while ((line = input.readLine()) != null) { System.out.println(line); } input.close(); } }