Creating a Maude Process.

The mechanism to create a Maude process in Java was initially based in the program Maude Workstation. To launch an external program from Java we use the method java.lang.Runtime.exec(String cmd), where the string "cmd" is the command to be executed. This method returns an instance of the class java.lang.Process. This instance is the one that permit us to control the launched process.

The more interesting methods that this class provides are getInputStream(), getOutputStream() and getErrorStream(). These methods return the streams that permit us to acces the standard input, output and error of the process respectively.

Writting in the input buffer properly we can send commands to Maude, and reading the output and error buffers, we can get the results or errors returned by Maude. Basically, the Java code that permits us to run and control one program is:

Process MaudeProcess = runTime.exec(commandString);


BufferedWriter buffStdin = new BufferedWriter(
        new OutputStreamWriter(MaudeProcess.getOutputStream()));


BufferedReader buffStdout = new BufferedReader(
        new InputStreamReader(MaudeProcess.getInputStream()));


BufferedReader buffStderr = new BufferedReader(
        new InputStreamReader(MaudeProcess.getErrorStream()));

We must say that the command to be executed is not directly Maude, but the shell program bash (in Windows we will use the Cygwin bash). We wil execute

bash -c echo $$; exec 'pathMaude' -interactive

This command allows us to deal with the interruptions to activate the debug mode in Maude, or to kill the process by means of the kill command.