2

I want to search logcat for a specific keyword using grep:

ProcessBuilder(
    listOf("logcat", "-d", "|", "grep", "<regex-match>")
).start().inputStream.use {
    BufferedReader(InputStreamReader(it)).forEachLine {
        ...
    }
}

But, I later found that this isn't really working, reason being that pipe results in another process. JDK 9 offers startPipeline() method as a way to counter this.

I don't see my android build with this API. Given upgrading JDK version is a long process in my case (if possible), is there a method to achieve the same result with current APIs?

PS: I tried looping though output of "logcat -d" and filtering, but that takes too much time.

Rohit
  • 475
  • 4
  • 18
  • 1
    common question... `|` is interpreted by some shell process, `ProcessBuilder` does not (but usually it can start a shell too) - [searching](https://stackoverflow.com/search?q=%5Bprocessbuilder%5D+pipe) for `[processbuilder] pipe` should find *some* question handling this problem... like [Using Java ProcessBuilder to Execute a Piped Command](https://stackoverflow.com/questions/3776195/using-java-processbuilder-to-execute-a-piped-command) – user16320675 Feb 19 '23 at 15:41
  • @user16320675 is correct. So if you want to use a pipe, start a shell, such as `bash -c .......` (if you have it on Android) – g00se Feb 19 '23 at 18:16

0 Answers0