daily pastebin goal
51%
SHARE
TWEET

Untitled

a guest Feb 19th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. for (String s : files)
  2.     String cmd = "adb -s 0123456789ABCDEF push " + s + " /mnt/sdcard/" + s;
  3.     try {
  4.         InputStream is = Runtime.getRuntime().exec(cmd).getInputStream();
  5.         while (is.read() != -1) {}
  6.     } catch (IOException e) {
  7.         e.printStackTrace();
  8.     }
  9.      
  10. java.io.IOException: Cannot run program "adb -s 0123456789ABCDEF push "inputfile "outputfile""": error=2, File or directory not found
  11.      
  12. public class Utils {
  13.     private static final String[] WIN_RUNTIME = { "cmd.exe", "/C" };
  14.     private static final String[] OS_LINUX_RUNTIME = { "/bin/bash", "-l", "-c" };
  15.  
  16.     private Utils() {
  17.     }
  18.  
  19.     private static <T> T[] concat(T[] first, T[] second) {
  20.         T[] result = Arrays.copyOf(first, first.length + second.length);
  21.         System.arraycopy(second, 0, result, first.length, second.length);
  22.         return result;
  23.     }
  24.  
  25.     public static List<String> runProcess(boolean isWin, String... command) {
  26.         System.out.print("command to run: ");
  27.         for (String s : command) {
  28.             System.out.print(s);
  29.         }
  30.         System.out.print("n");
  31.         String[] allCommand = null;
  32.         try {
  33.             if (isWin) {
  34.                 allCommand = concat(WIN_RUNTIME, command);
  35.             } else {
  36.                 allCommand = concat(OS_LINUX_RUNTIME, command);
  37.             }
  38.             ProcessBuilder pb = new ProcessBuilder(allCommand);
  39.             pb.redirectErrorStream(true);
  40.             Process p = pb.start();
  41.             p.waitFor();
  42.             BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
  43.             String _temp = null;
  44.             List<String> line = new ArrayList<String>();
  45.             while ((_temp = in.readLine()) != null) {
  46.                 System.out.println("temp line: " + _temp);
  47.                 line.add(_temp);
  48.             }
  49.             System.out.println("result after command: " + line);
  50.             return line;
  51.  
  52.         } catch (Exception e) {
  53.             e.printStackTrace();
  54.             return null;
  55.         }
  56.     }
  57. }
  58.      
  59. ProcessBuilder pb = new ProcessBuilder("adb", "-s", "0123456789ABCDEF", "push", inputfile, outputfile);
  60. Process pc = pb.start();
  61. pc.waitFor();
  62. System.out.println("Done");
  63.      
  64. public static void adbpush() {
  65.         System.out.println("adb push....");
  66.         String[] aCommand = new String[] { adbPath, "push", inputFile(String),OutputDirectory };
  67.         try {
  68.             // Process process = new ProcessBuilder(aCommand).start();
  69.             Process process = Runtime.getRuntime().exec(aCommand);
  70.             process.waitFor(3, TimeUnit.SECONDS);
  71.             System.out.println("file pushed");
  72.         } catch (Exception e) {
  73.             e.printStackTrace();
  74.         }
  75.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top