Java exec exec(String cmd)

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

Description

exec

License

Open Source License

Declaration

public static String exec(String cmd) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static String exec(String cmd) {
        Process process = null;/*from  w w  w .j av  a2 s.  co  m*/
        List<String> processList = new ArrayList<String>();
        try {
            process = Runtime.getRuntime().exec(cmd);
            BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String line = "";
            while ((line = input.readLine()) != null) {
                processList.add(line);
            }
            input.close();
            return processList.get(0);
        } catch (IOException e) {
            System.out.println("error");
            e.printStackTrace();
            return "error";
        }
    }
}

Related

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