Trying to run a simple script in Haskell by using java code. (Windows 10)
The haskell script looks like this:
import Data.Char(toUpper)
main = interact (map toUpper)
I have made an simple.exe file with ghc, and it works as expected from cmd module. I write a simple string and it replies with the same string in uppercase, and I can repeat this until I chose to stop the program.
But when I try to run this program through java it will not work that way. I can feed the input, but in order to get output I need to close the input feed.
public class Main {
public static void main(String[] args) {
try {
Process process = new ProcessBuilder("simple").start();
InputStream processInputStream = process.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(processInputStream));
OutputStream processOutputStream = process.getOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(processOutputStream));
char[] bt = ("Hello").toCharArray();
writer.write(bt);
writer.flush();
writer.newLine();
processOutputStream.close(); -- Only works if I close output stream,.
System.out.println(reader.readLine());
}catch (IOException e) {
e.printStackTrace();
}
}
}
How can I get output w/o closing my output-feed in java program.
Restarting the process works, but the execution time is horrible.
I have tried threading the program, with same result.