如何从 jar 读取 adb 响应?
How to read adb response from jar?
我正在尝试对一些应用程序安装进行批处理,我想逐个应用程序进行。
我正在尝试将 adb 命令响应放入我的 java 程序中,但我无法理解为什么我没有从 InputStream
!
中得到任何东西
这是我的测试代码:
import java.io.IOException;
import java.io.InputStream;
public class main_adbStreamTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
Process pro = Runtime.getRuntime().exec("platform-tools\adb.exe -s " + args[0] + ":5555 install -r " + args[1]); // + " >> " + SBCWLogger.getFileHandlerName()
//add installation verification
InputStream is = pro.getInputStream();
int i = 0;
while( (i = is.read() ) != -1) {
System.out.print((char)i);
}
//verification done
} catch (IOException e) {
e.printStackTrace();
}
}
}
我发现这个答案不起作用,而且我也无法正确使用 pro.getInputStream()
。
我也尝试了大多数 answers from here,但我测试的 none 有效。当我没有连接或安装失败时,我成功地读取了错误,但在安装结束时没有像 Success
这样的信息性消息。这就是我想要的。
编辑:由于 Onix 的回答,下面的代码正在运行。
import java.io.IOException;
import java.io.InputStream;
public class main_adbStreamTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
Process pro = new ProcessBuilder("platform-tools\adb.exe", "-s",args[0], "install", "-r", args[1]).start();
//add installation verification
InputStream is = pro.getInputStream();
int i = 0;
while( (i = is.read() ) != -1) {
System.out.print((char)i);
}
//verification done
} catch (IOException e) {
e.printStackTrace();
}
}
}
要获得著名的 Success
,只需将流写入文件并读取最后一行。
试试这个
Process process = new ProcessBuilder("Full path to adb", "-s", args[0], "install", "-r", args[1]).start();
InputStream is = process.getInputStream();
我正在尝试对一些应用程序安装进行批处理,我想逐个应用程序进行。
我正在尝试将 adb 命令响应放入我的 java 程序中,但我无法理解为什么我没有从 InputStream
!
这是我的测试代码:
import java.io.IOException;
import java.io.InputStream;
public class main_adbStreamTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
Process pro = Runtime.getRuntime().exec("platform-tools\adb.exe -s " + args[0] + ":5555 install -r " + args[1]); // + " >> " + SBCWLogger.getFileHandlerName()
//add installation verification
InputStream is = pro.getInputStream();
int i = 0;
while( (i = is.read() ) != -1) {
System.out.print((char)i);
}
//verification done
} catch (IOException e) {
e.printStackTrace();
}
}
}
我发现这个答案不起作用,而且我也无法正确使用 pro.getInputStream()
。
我也尝试了大多数 answers from here,但我测试的 none 有效。当我没有连接或安装失败时,我成功地读取了错误,但在安装结束时没有像 Success
这样的信息性消息。这就是我想要的。
编辑:由于 Onix 的回答,下面的代码正在运行。
import java.io.IOException;
import java.io.InputStream;
public class main_adbStreamTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
Process pro = new ProcessBuilder("platform-tools\adb.exe", "-s",args[0], "install", "-r", args[1]).start();
//add installation verification
InputStream is = pro.getInputStream();
int i = 0;
while( (i = is.read() ) != -1) {
System.out.print((char)i);
}
//verification done
} catch (IOException e) {
e.printStackTrace();
}
}
}
要获得著名的 Success
,只需将流写入文件并读取最后一行。
试试这个
Process process = new ProcessBuilder("Full path to adb", "-s", args[0], "install", "-r", args[1]).start();
InputStream is = process.getInputStream();