Java exec exec(String... command)

Here you can find the source of exec(String... command)

Description

exec

License

Open Source License

Declaration

public static String exec(String... command) throws IOException, InterruptedException 

Method Source Code


//package com.java2s;
/*/*from   www .j a v a  2  s  .c  o  m*/
 * Copyright (c) 2014 Peter Palaga.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Main {
    public static String exec(String... command) throws IOException, InterruptedException {
        Process p = Runtime.getRuntime().exec(command);
        p.waitFor();
        InputStream in = null;
        StringBuilder result;
        try {
            in = p.getInputStream();
            BufferedReader reader = new BufferedReader(new InputStreamReader(in));
            String line = null;
            result = new StringBuilder();
            while ((line = reader.readLine()) != null) {
                result.append(line + "\n");
            }
        } finally {
            if (in != null) {
                in.close();
            }
        }
        return result.toString();
    }
}

Related

  1. exec(String... _command)
  2. exec(String... args)
  3. exec(String... cmd)
  4. exec(String... cmdarray)
  5. exec(String... command)
  6. exec(String[] args)
  7. execAdbCmd(String cmd)
  8. execAndGetOutput(ProcessBuilder builder)
  9. execCmd(String cmd)