Run commands in a Java class
I am trying to run a program by command in a Java class. This program has a specific commands which I would like to execute in a Java program. Running this program in the command line would be as follow:
[user@mycomputer ~] xx
xx> draw(1,2)
....
...
...
xx>end()
[user@mycomputer ~]
I tried to do the following:
Code:
Process child = Runtime.getRuntime().exec("xx");
int returnCode = child.waitFor();
System.out.println("Return code = " + returnCode);
child = Runtime.getRuntime().exec("draw(1,2)");
returnCode = child.waitFor();
System.out.println("Return code = " + returnCode);
but it gave me the following error:
java.io.IOException: Cannot run program "draw(1,2)": java.io.IOException: error=2, No such file or directory
It seems that what this code did is equivalent to the following in the command line:
[user@mycomputer ~] xx
[user@mycomputer ~] draw(1,2)
It is supposed that draw(1,2) is executed under the program xx.
Any help would be appreciated.