LifeLongStudent
LifeLongStudent

Reputation: 2478

Scala get list of directories from Process

How to iterate process each line separate in ls -l command

val cmd = "ls -l"

I want to process each line separately in output. I want to filter the filenames which have _good in the output

cmd.!! dumps all content in single string

Upvotes: 0

Views: 110

Answers (1)

som-snytt
som-snytt

Reputation: 39577

You want to read the scaladoc for ProcessBuilder, which says

scala> Process("ls /tmp").lines
warning: there were 1 deprecation warning(s); re-run with -deprecation for details
res2: Stream[String] = Stream(at-spi2, ?)

scala> .toList
res3: List[String] = List(at-spi2, hsperfdata_apm, keyring-Lsl8gb, orbit-apm, pulse-2L9K88eMlGn7, pulse-Hcr7h8tFMGwW, pulse-PKdhtXMmr18n, sbt6769456248604563825.log, sbt_68f5ab55, sbt8158248552881459061.log, ssh-vAcOoXVi2053, tmpBuQ6hF, unity_support_test.0)

Also the package doc is verbose.

Upvotes: 1

Related Questions