Problem with function "system"

17 views
Skip to first unread message

denis.be...@gmail.com

unread,
Mar 17, 2025, 12:53:30 PMMar 17
to CLIPSESG
Is there anything special with embedding function "system" in other CLIPS functions?

1) Suppose I have  a (C) program (say "pgr") with a rather complex command line, more precisely:

pgr -f'%#.c' -qFN -e'uniq()' < ?input-file > ?output-file


Note 1: this works as expected on my Mac


2) Now suppose I want to wrap it in a CLIPS function, e.g.:

(deffunction CL-pgr (?input-file ?output-file)

    (bind ?cmd

        (str-cat

            pgr 

            "-f'%#.c' -qFN -e'uniq()'"

            " < " ?input-file

            " > " ?output-file

        )

    )

    (system ?cmd)

)


Note 2: this works as expected on my Mac

Note 2bis: there are many alternative ways to get it to work.



3) Now suppose I want to include this CLIPS function in e.g. a loop-for-count loop in which successive ?input and ?output files are defined before each call to CL-pgr.

It doesn't work.

More specifically, the -e'uniq()' part is not taken into account .


Does anyone understand what's happening here?


PS: I tried with CLIPS 6.3 and 6.4 (r952) on MacOS 15.3.2.

I use the generic settings of CLIPS.



CLIPS Support

unread,
Mar 18, 2025, 10:54:41 PMMar 18
to CLIPSESG
The CLIPS system function just passes its string argument to the standard C library system function. I wouldn't think there would be any issue of where it was called unless there was a bug somehow corrupting the string that was passed to the C system function.
What you could try is to create a small C program and just hardcode the successive system calls that your CLIPS program is making. Something like this:

#include <stdlib.h>


int main()

  {

   system("date");

   system("date -v1m -v+1y");

   system("date -v1d -v+1m -v-1d -v-fri");

  }


If the strange behavior continues to occur, then you'll know that the issue is unrelated to CLIPS.

CLIPSUnix % gcc -o test test.c

CLIPSUnix % ./test

Tue Mar 18 21:46:36 CDT 2025

Sun Jan 18 21:46:36 CST 2026

Fri Mar 28 21:46:36 CDT 2025

CLIPSUnix % 



Reply all
Reply to author
Forward
0 new messages