I am attempting to concatenate the content of two files using scala.sys.process.Process.cat and pipe the result as an input to a process. While doing so, I encountered very weird behaviour with only the first file being taken into account.
To figure out what exactly was going wrong, I created the following minimal example:
import scala.sys.process.Process
import java.io.File
object HelloWorld {
def main(args: Array[String]): Unit = {
(Process.cat(List(new File("hello"), new File("world"))) #> new File("helloworld")).!
}
}
When run, I would expect this code to concatenate the content of the files “hello” and “world”, and write them into the file “helloworld” (i.e. cat hello world > helloworld
in bash terms).
However when I run this code, the following happens:
bash-3.2$ scala -version
Scala code runner version 2.12.5 -- Copyright 2002-2018, LAMP/EPFL and Lightbend, Inc.
bash-3.2$ echo "hello" > hello
bash-3.2$ echo "world" > world
bash-3.2$ scala example.scala
bash-3.2$ cat helloworld
hello
bash-3.2$
It seems that Process.cat() simply ignores the second file and only uses the first one.
Can anybody help me and tell me what I am doing wrong?