Java exec execAdbCmd(String cmd)

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

Description

exec Adb Cmd

License

Apache License

Declaration

private static String execAdbCmd(String cmd) 

Method Source Code

//package com.java2s;
/*/*w w  w .j  av  a  2s  .  com*/
 * Copyright 2017 By_syk
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

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

public class Main {
    private static String execAdbCmd(String cmd) {
        String result = "";

        Runtime runtime = Runtime.getRuntime();
        Process process = null;
        BufferedReader bufferedReader = null;
        try {
            process = runtime.exec(cmd);
            bufferedReader = new BufferedReader(new InputStreamReader(
                    process.getInputStream(), "utf-8"));
            String buffer;
            while ((buffer = bufferedReader.readLine()) != null) {
                result += buffer + "\n";
            }
            if (result.length() > 0) {
                result = result.substring(0, result.length() - 1);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (bufferedReader != null) {
                try {
                    bufferedReader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (process != null) {
                process.destroy();
                process = null;
            }
        }

        return result;
    }
}

Related

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