Menu

Run CLIPS batch file from windows command prompt

Help
2016-06-08
2016-06-13
  • Hanan Mansour Mohamed

    Run CLIPS batch file from windows command prompt
    the batch file contain the following code
    (load "D:/CLIPS/with_gateways_interface_rules_servicesv12.CLP")
    (load "D:/CLIPS/mitigation3_.CLP")
    (reset)
    (run)
    y
    8
    zone1
    local
    1
    client1
    1
    account1
    standard
    y
    n
    y
    n
    y
    admin1
    1
    user1_clin1
    0
    zone2
    local
    1
    client500
    1
    account500
    standard
    y
    n
    y
    n
    y
    admin500
    1
    user500_clin500
    0
    zone3
    local
    1
    client96
    1
    account96
    standard
    y
    n
    y
    n
    y
    admin96
    1
    user96_clin96
    0
    zone4
    local
    4
    DC_SRV
    1
    administrator
    administrator
    n
    y
    adminDC
    1
    user1_DC_srv
    2
    RPC
    rpc
    SSH
    ssh
    DB_SRV
    1
    administrator
    administrator
    y
    n
    adminDB
    1
    user4_DB_srv
    1
    ORACLE_DB
    ora_db_port
    Mail_SRV
    1
    administrator
    administrator
    y
    n
    admin_Mail
    1
    user6_Mail_srv
    1
    MAIL
    smtp
    Web_SRV
    1
    administrator
    administrator
    y
    n
    admin_Web
    1
    user8_Web_srv
    2
    HTTP
    http
    FTP
    ftp
    zone5
    local
    1
    client192
    1
    account192
    standard
    y
    n
    y
    n
    y
    admin192
    1
    user192_clin192
    0
    internet
    internet
    n
    1
    devil
    1
    administrator
    administrator
    y
    n
    AA
    1
    attacker
    0
    zoneBB
    local
    0
    zoneUTM
    local
    0
    3
    firewall
    FW
    4
    zone1
    zone2
    internet
    zoneBB
    8
    AnyHost
    Web_SRV
    http
    permit
    0
    AnyHost
    Web_SRV
    ftp
    permit
    1
    AnyHost
    Mail_SRV
    smtp
    permit
    2
    AnyHost
    DB_SRV
    ora_db_port
    permit
    3
    AnyHost
    DC_SRV
    rpc
    permit
    4
    AnyHost
    DC_SRV
    ssh
    permit
    5
    AnyHost
    DC_SRV
    AnyPort
    deny
    6
    AnyHost
    AnyHost
    AnyPort
    deny
    7
    router
    BB
    4
    zoneBB
    zone3
    zone5
    zoneUTM
    utm
    UTM
    2
    zoneUTM
    zone4
    4
    AnyHost
    DC_SRV
    different
    AnyHost
    DB_SRV
    different
    AnyHost
    Web_SRV
    different
    AnyHost
    Mail_SRV
    different

     
  • Gary Riley

    Gary Riley - 2016-06-08

    If your batch file is named run.bat and is in the same directory as your executable named clips, you'd enter "clips -f run.bat".

    From the Basic Programming Guide:

    2.1.2 Automated Command Entry and Loading

    Some operating systems allow additional arguments to be specified to a program when it begins execution. When the CLIPS executable is started under such an operating system, CLIPS can be made to automatically execute a series of commands read directly from a file or to load constructs from a file. The command-line syntax for starting CLIPS and automatically reading commands or loading constructs from a file is as follows:

    Syntax:

    clips <option>*
    <option> ::= -f <filename> | -f2 <filename> | -l <filename>

    For the -f option, <filename> is a file that contains CLIPS commands. If the exit command is included in the file, CLIPS will halt and the user is returned to the operating system after executing the commands in the file. If an exit command is not in the file, CLIPS will enter in its interactive state after executing the commands in the file. Commands in the file should be entered exactly as they would be interactively (i.e. opening and closing parentheses must be included and a carriage return must be at the end of the command). The -f command line option is equivalent to interactively entering a batch command as the first command to the CLIPS prompt.

    The -f2 option is similar to the -f option, but is equivalent to interactively entering a batch* command. The commands stored in <filename> are immediately executed, but the commands and their return values are not displayed as they would be for a batch command.

    For the -l option, <filename> should be a file containing CLIPS constructs. This file will be loaded into the environment. The -l command line option is equivalent to interactively entering a load command.

     
  • Gary Riley

    Gary Riley - 2016-06-08

    In general, if you want to time the execution of one or more commands, you can use the timer function:

    (timer (reset) (run))

    The batch command is the exception to this statement because when executed it merely specifies a file to be used as a replacement for standard input. The contents of the file are retrieved after the batch command finishes executing, so wrapping the batch call in a timer call will not time the commands in the batch file.

    The batch* command directly executes the commands/functions found in the specified file, so you can use this rather than the batch command to time a batch file.

    (timer (batch* run.bat))

    Because batch* does not replace standard input, you can only include commands/functions in your batch file. So if your batch file also includes batch input for commands such as read and readline, you can not use batch* with timer.

    To time a batch file, I'd suggest wrapping it within another batch file and write the start and end times to a file:

    (close time)
    (open time.txt time "w")
    (printout t "Start time is " (time) crlf)
    (batch run.bat)
    (printout t "End time is " (time) crlf)
    (close time)
    
     
  • Hanan Mansour Mohamed

    Thanks alot for your help and support

     
  • Hanan Mansour Mohamed

    why this code doesn't work
    (close time)
    (open "d:\time.txt" time "w")
    (bind ?stime (time))
    (printout time "Start time is " ?stime crlf)
    (batch run11_new.bat)
    (bind ?etime (time))
    (printout time t "End time is " ?etime crlf)
    (bind ?exectime (- ?etime ?stime))
    (printout time t "exectution time equals " ?exectime crlf)
    (close time)

    [EVALUATION 1] variable stime is unbound
    [ARGACCES5] Function expected argument 2# to be of time integer or float

     
  • Gary Riley

    Gary Riley - 2016-06-13

    You're probably have a (clear) or (reset) command in your run11_new.bat file. Those commands will remove the values of any variables bound at the command prompt. I'd suggest temporarily saving the start time to a text file.

    (close time)
    (open "temp.txt" temp "w")
    (printout temp (time) crlf)
    (close temp)
    (reset)
    (timer (loop-for-count (?i 500000) (+ ?i ?i))) 
    (bind ?etime (time))
    (open "temp.txt" temp "r")
    (bind ?stime (read temp))
    (close temp)
    (remove "temp.txt")
    (bind ?exectime (- ?etime ?stime))
    (open "time.txt" time "w")
    (printout time "Start time is " ?stime crlf)
    (printout time "End time is " ?etime crlf)
    (printout time "Execution time equals " ?exectime crlf)
    (close time)
    
     

Log in to post a comment.