The writefile filter takes two arguments enclosed in parentheses, a filename and a message. Each argument should be a string filter:
    writefile (filename message)
    writefile ("output.cqo" str(fen \n))
    writefile ("sample.cqo" str("number white pieces: " #A \n))

The filename argument specifies the name of a file to write to. The first time writefile is invoked on a specific filename, that file is opened and any preexisting contents of that file are deleted.

All remaining invocations of writefile will append the message to the file filename. Using writefile forces CQL to run single-threaded.

The filename must have extension .cqo.

CQL will halt if the filename filter fails to match, the message filter fails to match, or the write fails for any reason.


The following code outputs to the file fens.cqo the FEN of the current position and the current game number, separated by a comma:
    cql(input hhdbvi.pgn)
    writefile ("fens.cqo"
               str(fen "," gamenumber \n))