80,352
社区成员
发帖
与我相关
我的任务
分享
public static String installSliently(String filePath) throws IOException {
String[] args = { "pm", "install", "-r", filePath };
ProcessBuilder processBuilder = new ProcessBuilder(args);
Process process = processBuilder.start();
try{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int read = -1;
baos.write("err:\n".getBytes());
InputStream errIs = process.getErrorStream();
try{
while ((read = errIs.read()) != -1) {
baos.write(read);
}
}finally{
errIs.close();
}
baos.write('\n');
baos.write("out:\n".getBytes());
InputStream inIs = process.getInputStream();
try{
while ((read = inIs.read()) != -1) {
baos.write(read);
}
}finally{
inIs.close();
}
byte[] data = baos.toByteArray();
return new String(data);
}finally{
process.destroy();
}
}