CAPL Script

OpenFileWrite

This reference collection includes Vector documentation reproduced with permission. Snippets may require configuration-specific symbols and are not all standalone programs. Sources and validation limits.

Contract and mode selection

dword openFileWrite(char filename[], dword mode);
dword openFileWrite(char filename[], dword mode, dword fileEncoding);

The return value is a nonzero output handle on success, or 0 on failure. The optional encoding parameter is a Microsoft code-page identifier.

Mode Access Consequence for an existing file
0 Text, overwrite Existing contents are overwritten
1 Binary, overwrite Existing contents are overwritten
2 Text, append New data is added at the end
3 Binary, append New data is added at the end

The destructive choice happens when opening: waiting until the first write to check whether a filename is safe is too late. First experiments must use a uniquely named disposable fixture, never the original recording or a report that needs preserving.

The output directory is part of the test

The reference requires a relative filename. setWritePath controls the output base; without it, the configuration directory is used. That base can be absolute or relative to the active configuration. Its reference also excludes distributed environments, so this local-file procedure is not a distributed test prescription.

Create the destination directory before running the test and verify its permissions. Do not assume the open operation creates a directory. Changing the write path also affects other documented consumers such as profile-writing functions; set up a dedicated test configuration rather than changing a shared path in the middle of unrelated work.

Append does not imply valid records

Suppose a previous file ends with 20 and no record separator. Appending 30\n produces 2030 on that line. Both writes can be successful while the numeric data becomes wrong. Appending also retains an earlier header or recording origin; adding another header or a timestamp sequence reset can invalidate downstream assumptions.

Choose overwrite for a newly generated, disposable complete dataset. Choose append only when the previous format, final separator and recording continuity are known. This is a data-format decision, not just a way to avoid losing a file.

Verify the entire operation

After opening succeeds, check each filePutString result and then check fileClose. A successful open does not prove that later writes succeeded. Reopen the exact output and inspect records; the input search path is not necessarily the output base.

For a fixture containing OLD, verify separately that mode 0 replaces it and mode 2 preserves it before adding the new record. Repeat with a deliberately unavailable destination and expect a controlled failure, not continued writes through handle 0. The validation walkthrough covers round-trip content and line-boundary tests.

This page combines the authorized API contract with independent failure analysis. No write operation has been executed against your CANoe environment. See sources and limits.