云守护的专栏

专注于移动安全、游戏安全、逆向安全 ;------------------------- 邮箱:1309521515@qq.com...

java exec shell cmd 用法

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

}

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/earbao/article/details/46817821
个人分类: java
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭