首页 > 解决方案 > 为什么 Java 将目录的 logcat 路径视为过滤器表达式?

问题描述

我需要将 logcat 从 Android 设备复制到 windows pc。Logcat 命令:

adb -s deviceUDID logcat -d > C:\logcat\logcat.log

从命令行成功运行。但是,如果我从代码运行它:

public void adbCommand(adbCommands theCommand) throws IOException {
        Log.info("Running ADB command : " + theCommand.get_command());

        Process exec = Runtime.getRuntime().exec(theCommand.get_command());
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(exec.getInputStream()));
        BufferedReader errorReader = new BufferedReader(new InputStreamReader(exec.getErrorStream()));
        new Thread(() -> {
            try {
                String line;
                while((line=bufferedReader.readLine())!=null){
                    Log.info(line);
                }
                while((line=errorReader.readLine())!=null){
                    Log.info("error: "+line);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }).start();

        try {
            exec.waitFor();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        Log.info("Done");

输出是:

adb -s deviceUDID logcat -d -s > C:\logcat\logcat.log 错误:无效的过滤器表达式 'C:\logcat\logcat.log'

任何想法这里有什么问题?谢谢!

标签: javaandroidadb

解决方案


将打印输出与手动输入的字符串进行比较:

Running ADB command : adb -s deviceUDID logcat -d -s > C:\logcat\logcat.log 
Pring to println :    adb -s deviceUDID logcat -d -s > C:\logcat\logcat.log –
Manually entered:     adb -s deviceUDID logcat -d > C:\logcat\logcat.log

有一个额外的 -s


推荐阅读