Here you can find the source of runShellCommand(String command)
Parameter | Description |
---|---|
command | a parameter |
public static void runShellCommand(String command)
//package com.java2s; //License from project: Apache License import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { /**//from w ww. j a v a2s . c o m * Run synchronous shell command and wait till it finishes * @param command */ public static void runShellCommand(String command) { try { System.out.println(command); Runtime rt = Runtime.getRuntime(); Process pr = rt.exec(command); BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream())); String line = null; while ((line = input.readLine()) != null) { System.out.println(line); } int exitVal = pr.waitFor(); System.out.println("Exited with error code " + exitVal); } catch (Exception e) { System.out.println(e.toString()); e.printStackTrace(); } } }