
Thanks a lot for the sugestions!
I am going to try them...
pedro
On 4/5/06, Björn Bringert
Benjamin Franksen wrote:
On Wednesday 05 April 2006 20:32, Pedro Miguel Duarte wrote:
I am writing a Java program with a call to a Haskell module M.hs, in order to evaluate some expression expr.
A very simple idea, which I got somewhere in the net, is to create a Process object p which executes a GHC command-line instruction:
Process p = Runtime.getRuntime(); p.exec( " ghc M.hs -e \"expr\" " );
This would be very simple, if it worked...
My problem is that expressions i want to evaluate involve strings, and GHC command-line 'ghc' misinterprets some special symbols when it parses double quoted strings.
For instance, ghc -e " reverse \"2<3\" " gives an error!
Hmm. On my Linux machine (running zsh):
ben@sarun: .../play/ghc-e > ghc -e " reverse \"2<3\" " "3<2"
But now I see that you run 'p.exec' in Java which probably translates (more or less) to a 'exec' system call. 'exec' is not a shell, it cannot translate complex quotings and unquotings. I would try
p.exec( "/bin/sh ghc M.hs -e \"expr\" " );
or something similar.
Another way could be to use one of the other exec() methods (which BTW are available from the Runtime class, not the Process class). For example, using the "exec(String[] cmdarray)" version, you could write something like (not tested):
Runtime r = Runtime.getRuntime(); Process p = r.exec(new String[]{"ghc", "-e", expr});
/Björn