Here you can find the source of exec(String cmd)
public static void exec(String cmd)
//package com.java2s; /*//w ww. ja v a2 s . co m * Copyright (c) 2010, James Hanlon * All rights reserved. * * Made available under the BSD license - see the LICENSE file */ import java.io.IOException; import java.io.InputStream; public class Main { public static void exec(String cmd) { try { Process child = Runtime.getRuntime().exec(cmd); child.waitFor(); InputStream in = child.getInputStream(); int c; while ((c = in.read()) != -1) { System.out.print(c); } in.close(); } catch (IOException e) { System.err.println("Error: could execute command: " + cmd); e.printStackTrace(); } catch (InterruptedException e) { System.err.println("Error: command interrupted: " + cmd); e.printStackTrace(); } } }