Siebel eScript Language Reference > Siebel eScript Commands > File I/O Methods in eScript >

Clib.freopen() Method

This method closes the file associated with a file pointer and then opens a file and associates it with the file pointer of the file that has been closed.


Clib.freopen(filename, mode, oldFilePointer)



The name of a file to be opened


One of the file modes specified in the Clib.fopen() function; for Unicode, the same "u" flag as in Clib.fopen can be used


The file pointer to a file to be closed and to which filename is to be associated


A copy of the old file pointer after reassignment, or null if the function fails.


This method closes the file associated with oldFilePointer (ignoring any close errors) and then opens filename according to mode (as in Clib.fopen()) and reassociates oldFilePointer to this new file specification. It is commonly used to redirect one of the predefined file handles (stdout, stderr, stdin) to or from a file.


The following sample script writes to two different files using the same filepointer.

var oFile = Clib.fopen("c:\\temp\\firstfile","w");
if (oFile == null)
   TheApplication().RaiseErrorText("File not found.");
Clib.fprintf(oFile, "Writing to first file\n");
Clib.freopen("c:\\temp\\secondfile", "w", oFile);
if (oFile == null)
   TheApplication().RaiseErrorText("File not found.");
Clib.fprintf(oFile, "Writing to second file\n");

See Also

Clib.getenv() Method
Clib.fopen() Method

Siebel eScript Language Reference