|
From: Michael B. <mb...@zg...> - 2002-04-05 11:35:38
|
Hi Vitor,
i'm working with Oliver who recently sent you an email concerning
problems with pipes in Yap.
We are using Yap 4.3.20 with Linux (2002-01-03) from Sourceforge and
the precompiled binaries for Windows NT4.0 also from Sourceforge.
I think it's easier to explain our little problem if I send you a code
example:
Yap file (YapConnect.txt) looks like this:
:- use_module(library(system)).
:- dynamic(connect/2).
init_connect :-
exec('java StoryFrame',[pipe(Message), pipe(Answer), null],_),
retractall(connect(_,_)),
assert(connect(out,Message)),
assert(connect(in,Answer)).
send(Msg) :-
connect(out,Stream),
write(Stream,Msg),
flush_output(Stream).
send_nl :-
connect(out,Stream),
nl(Stream),
flush_output(Stream).
receive(Msg) :-
connect(in, Stream),
read(Stream,Msg).
:- init_connect.
:- send('First Hello').
:- send_nl.
:- receive(Message), write(Message).
:- send('Second Hello').
:- send_nl.
:- receive(Message), write(Message).
Java file (StoryFrame.java) looks like this:
import java.io.*;
class StoryFrame {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new
InputStreamReader(System.in));
Writer out = new BufferedWriter(new OutputStreamWriter(System.out));
FileWriter log = new FileWriter("logfile.txt");
String input = null;
while ((input = in.readLine()) != null) {
log.write("Received: "+ input +"\n");
if (input.equals("First Hello")) {
System.out.println("FirstHello.");
log.write("Sent: FistHello.\n");
log.flush();
}
if (input.equals("Second Hello")) {
System.out.println("SecondHello.");
log.write("Sent: SecondHello.\n");
log.flush();
}
}
System.out.println("THE_END.");
log.write("Sent: THE_END.\n");
log.flush();
}
}
Now if we start up yap and do a:
['YapConnect.txt'].
Yap sends the two 'Strings' and Java returns the right messages. (Tested
with the logfile: logfile.txt)
We are back at the Yap-command prompt.
Now we type the following two lines at the command prompt:
send('First Hello').
send_nl.
The problem is, that nothing is sent to the Java Program anymore!
(Tested again with the logfile)
It seems that the connection is broken, although the Java Program is
still running! (No 'THE_END' in the logfile)
Is there a way to keep the connection alive? Are we doing something
wrong or is it supposed to work that way?
The other problem only occured under Windows (NT4.0 and 98) with Yap
Version 4.3.20 precompiled binaries:
We are not able to build up a connection at all. We are using the same 2
files (YapConnect.txt and StoryFrame.java) but nothing is sent to the
Java Program.
Is it possible to connect the streams under the Windows enviroment?
Again, are we doing something wrong? Should we not use the precompiled
binaries?
One last question: Is it possible to disable the 'reading from pipe x'
message for every character read?
Thanks for your help in advance!
Regards
Michael
|