如何在文件中保存 logcat 的内容并同时更改 logcat 的格式?

how do I save contents of logcat in a file and change the format of the logcat at the same time?

String fileName = "somefile.txt";
File outputFile = new File(context.getDir("somedirectory", 0), fileName);
Runtime singleton = Runtime.getRuntime();
singleton.exec("logcat -v long"); //set the output format       
singleton.exec("logcat -f " + outputFile.getAbsolutePath()); //format somehow reset to default here :/

此代码创建一个文件并在其中存储 logcat 但我无法将格式更改为 long。我相信这是因为 exec 函数是两个不同的进程,它们必须是一个。但我不确定该怎么做。

您现在执行此操作的方式实际上执行了两个 logcat 命令 - 第一个带有 -v 选项,第二个带有 -f 选项。
您没有看到第一个命令的任何输出的原因是您没有定义它应该去哪里。
您应该将选项组合在一起:singleton.exec("logcat -v long -f myfile");