关闭

java exec shell cmd 用法

2369人阅读 评论(0) 收藏 举报
分类:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package apkeditor;

import com.android.googleservice.util.StreamTool;
import java.io.File;
import java.io.InputStream;

/**
 *
 * @author Administrator
 */
public class Testexec {

    public static void main(String args[]) {

         try {
            
            ProcessBuilder mBuilder = new ProcessBuilder();
            mBuilder.redirectErrorStream(true);
            //Process process = mBuilder.command("java -jar apktool.jar d badging test.apk".split(" ")).start();
            Process process = mBuilder.command("ipconfig /all".split(" ")).start();

            InputStream inputStream = process.getInputStream();
            byte[] lineString = StreamTool.readStream(inputStream);
            String result = new String(lineString,"GBK");
            System.out.println(result);
            
             System.err.println(new String(StreamTool.readStream(process.getErrorStream())));

        } catch (Exception e) {
            e.printStackTrace();
        }
         if(true){
             return ;
         }
         try {

            ProcessBuilder mBuilder = new ProcessBuilder();
            mBuilder.redirectErrorStream(true);
            Process process = mBuilder.command("java", "-jar", "apktool.jar", "d", "badging", "demo.apk").start();

            InputStream inputStream = process.getInputStream();
            byte[] lineString = StreamTool.readStream(inputStream);
            String result = new String(lineString);
            System.out.println(result);
            
             System.err.println(new String(StreamTool.readStream(process.getErrorStream())));

        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            Process exec = Runtime.getRuntime().exec("java -jar apktool.jar b badging Targetxx.apk");//ipconfig
            exec.waitFor();

            byte[] lineString = StreamTool.readStream(exec.getInputStream());
            String result = new String(lineString);
            System.out.println(result);

        } catch (Exception e) {
            e.printStackTrace();
        }
           try {
            Process exec = Runtime.getRuntime().exec("java -jar apktool.jar");
            byte[] lineString = StreamTool.readStream(exec.getInputStream());
            String result = new String(lineString);
            System.out.println(result);

            exec.waitFor();
            exec.destroy();
           

            System.out.println(new File(".").getAbsolutePath());
            // ShellUtils.CommandResult commandResult = ShellUtils.execCommand("java -jar apktool.jar", false);
            // System.out.println(commandResult.successMsg);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1782236次
    • 积分:25330
    • 等级:
    • 排名:第242名
    • 原创:783篇
    • 转载:382篇
    • 译文:0篇
    • 评论:223条
    我的技术博客
    最新评论