Let's Java start and handle prolog program
Hi,
I have to make a java program that send an input to a working-completed-prolog program and get the output from it and handle the string result... I know that to run this prolog program i have to send those commands:
api.exe (that launch the prolog environment) <--
[new]. <--
new. <--
start. <--
where <-- is the return button. Then i should be able to send the input taken from java program and be able to get the returned string.
Anybody has any idea on how to do that? Should i install any package?
Thanks in advance for any replies.
Bye
[621 byte] By [
Hanz0a] at [2007-10-2 6:07:35]

Use Runtime.exec to launch the application ("api.exe"). That returns a Process object.
Use methods on the Process object to get the process's input stream and output stream. Write the appropriate strings to the output stream. Read from the input stream.
Also read this article:
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
i tried to do that with following code:
Runtime r = Runtime.getRuntime();
Process p = null;
String str;
String cmd = "c:/Programmi/Parser/API.exe";
try {
p = r.exec(cmd);
} catch (IOException ex) {
System.out.println("error");
}
InputStream in = p.getInputStream();
int c;
try {
while ((c = in.read()) != -1) {
System.out.print((char) c);
}
} catch (IOException ex1) {
}
try {
in.close();
} catch (IOException ex2) {
}
int exitVal = 0;
try {
exitVal = p.waitFor();
} catch (InterruptedException ex3) {
}
System.out.println("Process exitValue: " + exitVal);
and i doesn't get any logs back. i tried to do:
String cmd = "c:/Programmi/Parser/API.exe";
and it worked, i got the ipconfig output in my java console.
API.EXE once it's run, print 2 lines and a prompt command taht wait for command.
Shouldn't i get the 2 lines it prints?
What's exit value 1?
Executing the command, shouldn't the program not end since API.exe waits for user commands?
Any help is very appreciated
Thanks
Hanz0a at 2007-7-16 13:08:12 >

forgot to say that the output of the java program is:Process exitValue: 1bye
Hanz0a at 2007-7-16 13:08:12 >

seems like that the java program exists before API.exe get to prompt state. tried to do a .bat file with: (esegui.bat)
cd\
cd c:\programmi\parser
start API.exe
a dos windows appear with title API.EXE but then java program exit and dos window remain opened, with _ cursor flashing, but i don't see the first 2 lines that API.EXE should print.
If i do:
p = r.exec("cmd /c start c:\\Programmi\\Parser\\esegui.bat");
then the 2 dos window stay open and API.exe one show the 2 lines, while java program wait that the .bat one ends. The problem is that if i want to send command to API.EXE how can i do?
Hanz0a at 2007-7-16 13:08:12 >

Don't catch exceptions, and do nothing with them!> What's exit value 1?Normally 0 == success, !0 == failure.As to what '1' is, you will need to check the docs for your application.
mlka at 2007-7-16 13:08:12 >

if anybody want to try:
http://mio.discoremoto.virgilio.it/bidibibodibibu
there is parser.zip, unzip, and the file i need to run is:
api.exe.
Then i need to do those commands:
[new].
new.
start.
(with dot too). I need to catch output and send above commands.
Let me know if anybody had time to loose trying :)
Hanz0a at 2007-7-16 13:08:12 >

Does DOS support:echo "[new].new.start." | api > output.txt
mlka at 2007-7-16 13:08:12 >

i haven't understand what u're telling me to try. can u be give me more details please?
Hanz0a at 2007-7-16 13:08:12 >

> i haven't understand what u're telling me to try. can> u be give me more details please?Use a pipe to give the input, and a redirect to send the output to a file, run, then read in the file.
mlka at 2007-7-16 13:08:12 >

that's the point, how can i do that?
Hanz0a at 2007-7-16 13:08:12 >

if u try to download the program, u will see that the dos code u wrote doesn't work (was meant to be put in a .bat file right?).. Any other possible solution?
Hanz0a at 2007-7-16 13:08:12 >
