Question: I'm trying to create a program to compare the amount of time it takes various haskell scripts to run, which will later be used to create graphs and displayed in a GUI. I've tried to create said GUI using Haskell libraries but I haven't had much luck, especially since I'm having trouble finding up to date GUI libraries for Windows. I've tried to use Java to get these results but either get errors returned or simply no result. 

I've constructed a minimal example to show roughly what I'm doing at the moment:

```
    import java.io.*;
public class TestExec {
    public static void main(String[] args) {
        try {
            Process p = Runtime.getRuntime().exec("ghc test.hs 2 2");
            BufferedReader in = new BufferedReader(
                                new InputStreamReader(p.getInputStream()));
            String line = null;
            while ((line = in.readLine()) != null) {
                System.out.println(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

```

And here is the Haskell script this is calling, in this case a simple addition:

```
test x y =  x + y

```

Currently there simply isn't any result stored or printed. Anyone have any ideas?

Answer: 
This is mostly a Java question. Search for [Runtime.getRuntime().exec()](https://stackoverflow.com/search?q=java+Runtime.getRuntime+exec).

On the Haskell side, you need to write a stand-alone Haskell script. [The one](https://stackoverflow.com/a/20474463/25450) by @jozefg is OK. You should be able to run it as

```
runghc /path/to/script.hs 1 2

```

from the command line.

Calling it from Java is no different than running any other external process in Java. In Clojure (a JVM language, I use it for brevity) I do:

```
user=> (def p (-> (Runtime/getRuntime) (.exec "/usr/bin/runghc /tmp/test.hs 1 2")))
#'user/p
user=> (-> p .getInputStream input-stream reader line-seq)
("3")

```

Please note that I use `runghc` to run a script (not `ghc`). Full paths are not necessary, but could be helpful. Your Java program can be modified this way:

```
--- TestExec.question.java
+++ TestExec.java
@@ -2,7 +2,7 @@
 public class TestExec {
     public static void main(String[] args) {
         try {
-            Process p = Runtime.getRuntime().exec("ghc test.hs 2 2");
+            Process p = Runtime.getRuntime().exec("/usr/bin/runghc /tmp/test.hs 2 2");
             BufferedReader in = new BufferedReader(
                                 new InputStreamReader(p.getInputStream()));
             String line = null;

```

The modified version runs the Haskell script just fine. You may have to change paths to you `runghc` and `test.hs` locations.
At first to read from output you need to use `OutputStreamReader(p.getOutputStream())` instead of `InputStreamReader`