What I would like to do is wrap my Java program around the GHCI
.
In my mind it should work like this:
- Starting my Java program
- Write down some Haskell function as Input for Java (i.e. reverse [1,2,3,4])
- See the appropriate Haskell Output on my Java Console
Because I did not want to mess around with any language bridges I tried the clumsy way and used the Runtime.exec()
approach.
This is my Code:
public static void main(String[] args) throws Exception {
Runtime r = Runtime.getRuntime();
Process p = r.exec("ghci");
OutputStream output = p.getOutputStream();
output.write("let x = 5\r\n".getBytes());
output.write("x".getBytes());
int tmp;
String result = "";
while ((tmp = p.getInputStream().read()) != -1) {
result += (char) tmp;
}
System.out.println(result);
p.destroy(); }
My problem here is that the read() method always returns a -1 and I cannot get the output. I dont even know if what I wrote created any Output.
Help would be appreciated. Thanks!