Section 11: TSP command reference Model 2601B-PULSE System SourceMeter Instrument Reference Manual
11-84 2601B-PULSE-901-01A April 2020
fileVar:flush()
This function writes buffered data to a file.
Usage
fileVar:flush()
The file descriptor variable to flush
Details
The fileVar:write() or io.write() functions buffer data, which may not be written immediately
to the USB flash drive. Use fileVar:flush() to flush this data. Using this function removes the
need to close a file after writing to it, allowing the file to be left open to write more data. Data may be
lost if the file is not closed or flushed before a script ends.
If there is going to be a time delay before more data is written to a file, and you want to keep the file
open, flush the file after you write to it to prevent loss of data.
Example
local fileName = "/usb1/myfile.txt"
if fs.is_file(fileName) then
os.remove(fileName)
print("Removing file")
else
print("Nothing removed")
end
errorqueue.clear()
print("\n*** io.read")
myfile, myfile_err, myfile_errnum = io.open(fileName, "w")
myfile:write("Line 1\n")
myfile:flush()
myfile:close()
do
fileHandle = io.input(fileName)
value = io.read("*a")
print(value)
end
fileHandle:close()
print(errorqueue.next())
Writes data to a USB flash drive.
Also see
fileVar:write() (on page 11-88)
io.open() (on page 11-104)
io.write() (on page 11-108)