SYS_FileWriteValue Function

Action

Writes structured data, for example a 4Test record, directly to a file on a target machine.

Syntax

SYS_FileWriteValue (hFile, aValue)
Variable Description
hFile A handle to the file to write to. HFILE.
aValue The data to write to the file. ANYTYPE.

Notes

  • SYS_FileWriteValue is executed by the agent process, not the Silk Test Classic process; but it is essentially the same as FileWriteValue. To affect the host process, use the function with the hHost notation or machine handle operator. For more information about the machine handle operator and hHost, see Machine handle operator.

  • You can get a handle to a file (an HFILE) by calling the SYS_FileOpen function with the filemode data type set to either FM_WRITE, FM_UPDATE, or FM_APPEND.

  • SYS_FileWriteValue writes each piece of data (aValue) on its own line in hFile. For example, if you call SYS_FileWriteValue three times on a new file, the resulting file will have three lines.

  • You can specify any 4Test data type as aValue. Data is written to the file as follows:
    • Strings are enclosed by double quotation marks.

    • Numbers are not enclosed by quotation marks.

    • Composite data (such as lists and records) are enclosed by curly braces with elements separated by commas.

  • You can use SYS_FileReadValue to read files created with SYS_FileWriteValue.

  • The file functions that control writing to a file do not test your accessibility to a file. This means that you cannot write information to a file that has been opened in read only mode with FileOpen(). The function will successfully return, but no information is actually written to the file. There is no error message that indicates this.

  • This function is not designed for local access.

Example

[-] type PERSON is record
	[ ] STRING sName
	[ ] INTEGER iAge 
	[ ] 
[-] STRING sFile = "people.dat"
	[ ] 
[-] testcase SYS_WriteToFile ()
	[-] LIST OF PERSON lPerson = {...}
		[ ] {'Bob', 46}
		[ ] {'Emily', 16}
		[ ] {'Craig', 13}
	[ ] STRING sText = "Number of people:"
	[ ] INTEGER iCount = ListCount (lPerson)
	[ ] HFILE hFile
	[ ] PERSON Person
	[ ] 
	[ ] hFile = SYS_FileOpen (sFile, FM_WRITE) // Open the file 
	[ ] 
	[ ] // write header information 
	[ ] SYS_FileWriteValue (hFile, sText)
	[ ] SYS_FileWriteValue (hFile, iCount)
	[ ] 
	[ ] // write the data 
	[-] for each Person in lPerson // Write to the file 
		[ ] SYS_FileWriteValue (hFile, Person)
	[ ] SYS_FileClose (hFile) // Close the file
	[ ] 
	[ ] // Resulting contents of people.dat:
	[ ] // "Number of people:" 
	[ ] // 3
	[ ] // {"Bob", 46}
	[ ] // {"Emily", 16}
	[ ] // {"Craig", 13}