I think Mike Coburn wrote: > Hi Jess-Users, > > >From the following snippet: > > Rete engine = new Rete(); > > Value val = engine.executeCommand("(facts)"); > > how can I get the result of the jess command (facts) for example, > but really from any command, as a string or stringbuffer in order > to parse the result?
All Jess functions have a return value (which is the Value you get from executeCommand above,) and some Jess functions also print output to the screen. In the case of "facts" the return value is always TRUE (not interesting) and the list of facts is printed. You can capture what Jess prints to the screen by redirecting the standard I/O routers. Section 4.4.6 of the Jess manual talks about this in detail. It can be as simple as StringWriter writer = new StringWriter(); engine.addOutputRouter("WSTDOUT", writer); Now the output of "facts" will end up in this StringWriter. But it's rare that you actually want to do this just so you can parse the output; most of the time the only reason to do it is to embed Jess in a GUI and force the output to appear in a JTextArea or similar. The reason it's rare is because it's silly to make Jess turn this information into text, and then parse the text, when the information is available directly from Jess in a more useful form. In the case of the "facts" function, there's the method listFacts() in the Rete class, which returns an Iterator over all the Fact objects in working memory. Instead of doing the above, just call listFacts() and you have the same information much more efficiently. --------------------------------------------------------- Ernest Friedman-Hill Science and Engineering PSEs Phone: (925) 294-2154 Sandia National Labs FAX: (925) 294-2234 PO Box 969, MS 9012 [EMAIL PROTECTED] Livermore, CA 94550 http://herzberg.ca.sandia.gov -------------------------------------------------------------------- To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]' in the BODY of a message to [EMAIL PROTECTED], NOT to the list (use your own address!) List problems? Notify [EMAIL PROTECTED] --------------------------------------------------------------------