Here you can find the source of sendCommand(String path, String cmd)
public synchronized static void sendCommand(String path, String cmd)
//package com.java2s; //License from project: Apache License import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.File; import java.io.InputStreamReader; public class Main { public synchronized static void sendCommand(String path, String cmd) { new Thread(() -> { Runtime run = Runtime.getRuntime(); try { Process p = run.exec(cmd, null, new File(path)); BufferedInputStream in = new BufferedInputStream(p.getErrorStream()); BufferedReader inBr = new BufferedReader(new InputStreamReader(in)); String lineStr;/* www. j ava2 s .co m*/ while ((lineStr = inBr.readLine()) != null) { System.out.println(lineStr); } p.waitFor(); inBr.close(); in.close(); } catch (Exception e) { e.printStackTrace(); } }).start(); } }