Java exec exec(String cmd)

Here you can find the source of exec(String cmd)

Description

exec

License

Open Source License

Declaration

public static void exec(String cmd) 

Method Source Code

//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();
        }
    }
}

Related

  1. exec(ArrayList args, File path)
  2. exec(File dir, String cmd)
  3. exec(final String cmd, final String[] args, final byte[] in, final File dir)
  4. exec(List cmd, File binDir, File workDir, boolean parseOutput, boolean tossErrorOutput)
  5. exec(String args)
  6. exec(String cmd)
  7. exec(String cmd)
  8. exec(String cmd)
  9. exec(String cmd)