I need to run a shell command from a Scala script, and for this I use the following snippet:
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 is working fine. I wonder 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 equivalent to IMO for ls /tmp?
source
share