通过java通过wifi从adb获取logcat
我想通过java通过wifi将logcat从android设备传输到PC。程序将按时间获取logcat,并在单击按钮时停止 因此,我可以通过wifi连接到android并获取logcat:通过java通过wifi从adb获取logcat,java,android,adb,Java,Android,Adb,我想通过java通过wifi将logcat从android设备传输到PC。程序将按时间获取logcat,并在单击按钮时停止 因此,我可以通过wifi连接到android并获取logcat: adb -s [ip_address]:5555 logcat -v time > D:\logcat.txt 该命令在cmd中运行良好。当我按下Ctrl+C时,它停止。但是当我在java代码中运行这个命令时 Process proc; String command = "adb -s [ip_add
adb -s [ip_address]:5555 logcat -v time > D:\logcat.txt
该命令在cmd中运行良好。当我按下Ctrl+C时,它停止。但是当我在java代码中运行这个命令时
Process proc;
String command = "adb -s [ip_address]:5555 logcat -v time > D:\\Test_logcat.txt";
Runtime rt = Runtime.getRuntime();
try {
proc = rt.exec(command);
BufferedReader stdInput = new BufferedReader(new InputStreamReader(
proc.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(
proc.getErrorStream()));
String line = null;
while ((line = stdInput.readLine()) != null)
System.out.println(line);
while ((line = stdError.readLine()) != null) {
System.out.println(line);
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
它引发了以下错误:
/system/bin/sh: can't create D:\Test_logcat.txt: Read-only file system
嗯。我搜索了谷歌,找到了这个问题的答案,他们解释说:
In your command line example, you are running the ADB command from the Android terminal with / as current directory. So Android tries to write the output to /logcat.txt, which fails.
但是,我不明白为什么这个命令可以在cmd中正常运行,而不能在java程序中运行。这里的诀窍是什么
此外,你们这些好人能帮我解决这个问题吗?尝试使用logcat-v time-d>/mnt/local/log.txt
注意:用于存储数据的文件夹取决于设备,是否需要更改文件路径。如果从命令行运行此文件夹,则在电脑上执行。但如果从程序运行此文件夹,则在Android设备上执行。转到cur命令行并执行adb shell。现在你在你的Android外壳中。在这里,您可以执行与您的程序相同的命令。谢谢您的回答。如果我运行一个命令logcat-v time>/sdcard/logcat.txt,它看起来不错。但是,我想在程序中运行它,而不是在命令行中。>D:\\Test\u logcat.txt在第一种情况下由cmd解释,在第二种情况下由android shell解释,在这种情况下它无法创建此文件。尝试从java直接读取输出并将其写入文件在程序中使用logcat-v time-d>/sdcard/logcat.txt