简体   繁体   中英

Java: Writing to a Scala Output Stream

I'm working on a project that requires me to run an instance of scala using the Process class. To do this I execute the following code:

Process process = RunTime.getRunTime().exec("<path to scala binary> <scala file>");

This call gives me a process representative of the scala program that is executing. I am able to access the process's input stream and receive input from the process with:

BufferedReader stdin = new BufferedReader(new InputStreamReader(process.getInputStream()));
stdin.readLine();

The scala program I am trying to run involves a Scanner which picks up input and prints it out. When I try to register a BufferedWriter to the OutputStreamWriter that is generated from process.getOutputStream(), and then write to that stream with:

stdout.write("Hello");

The scala program does not receive this input, and I was wondering: why does this occur?

事实证明我忘了冲洗流。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM