I need to run a shell command from a Scala script and I use the following snippet for that:
import scala.sys.process.{Process, ProcessIO}
val command = "ls /tmp"
val process = Process(command)
val processIO = new ProcessIO(_ => (),
stdout => scala.io.Source.fromInputStream(stdout).getLines.foreach(println),
_ => ())
process.run(processIO)
The code works fine. I'm wondering why I get
java.io.IOException: Cannot run program "cd": error=2, No such file or directory
as soon as I change the command to cd /tmp && ls
which is IMO equivalent to ls /tmp
?