java执行带有重定向命令不成功的解决方案

之前的执行方法:

String path = "E:/screenshot.png";
String cmd = "adb exec-out screencap -p > " + path;
Runtime.getRuntime.exec(cmd);

执行不成功

之后的执行方法

String path = "E:/screenshot.png";
String cmd = "adb exec-out screencap -p > " + path;
String [] command = {"cmd" , "/C" , cmd};
Process process = Runtime.getRuntime().exec(command);

执行成功

这样执行也可以,两个时间差不多

String path = "E:/screenshot.png";
String cmd = "adb exec-out screencap -p > " + path;
String [] command = {"cmd" , "/C" , cmd};
ProcessBuilder pb = new ProcessBuilder(command);
Process p = pb.start();

你可能感兴趣的:(java执行带有重定向命令不成功的解决方案)