I need to process some text output from a long running command on windows. To get the results of this process as early as possible i am using the Scala Stream and ProcessBuilder class.
Everything runs flawless, but i run into a character encoding problem.
Here is my striped down source code (the powershell command is just a substitution for the real executable).
import scala.sys.process._
object CP850TEST extends Application{
val cmd = Seq("powershell", "-command", "echo 1a; Start-Sleep -s 1; echo 2äüîß; Start-Sleep -s 1 ; echo 3end")
val lines:Stream[String] = cmd.lines
lines.foreach(println)
}
The Output schould looks like:
1a
2äüîß
3end
but displays only:
1a
2����
3end
To solve this Problem in Java, I would declare the charset (Cp850) of the InputStream, but I can't find any solution in Scala:
public static void main(String[] args) throws IOException {
ProcessBuilder pb = new ProcessBuilder("powershell", "-command", "echo 1a; Start-Sleep -s 1; echo 2äüîß; Start-Sleep -s 1 ; echo 3end");
Process process = pb.start();
Scanner scanner = new Scanner(process.getInputStream(), "Cp850");
while ( scanner.hasNextLine() ) {
String s = scanner.nextLine();
System.out.println( s );
}
scanner.close();
}