0
votes

I am trying to find a way to get a directory listing from a running CLIPS program. The end goal is to have my CLIPS program run, find a set of files of facts to load into CLIPS, and then to run my rules.

According to http://www2.cs.siu.edu/~rahimi/cs537/slides/big-2.pdf, I tried

(defrule list-the-directory 
=>
  (printout t (system “ls ” “*.txt”) crlf)
)

That function call completed without an exception but returned nothing.

Oh, I am running CLIPS 6.3 on Mac OS X.

Thanks in advance for any help.

Bernie

1

1 Answers

1
votes

The CLIPS system function calls the C system library function. Any output from the system call is going to be directed to the terminal/console (C standard output). If you're running CLIPS as a terminal/console application, you'll see the output directed to the terminal/console. If you're using the CLIPS IDE, you won't see any output from C standard output because the IDE dialog window is capturing and displaying output directly from CLIPS.

If you direct the output from the system command to a file, you can open the file and print its contents using CLIPS I/O commands:

(defrule list-the-directory
   =>
   (system "ls > out.txt")
   (open "out.txt" out "r")
   (bind ?line (readline out))
   (while (neq ?line EOF)
      (printout t ?line crlf)
      (bind ?line (readline out)))
   (close out))

If you use the Load Constructs... menu command to load your rules, the directory will be set to the directory containing the rules and you can specify a partial directory path when creating and opening the file. Otherwise, you'll need to specify the full file path.