UWRITE Command

The UWRITE command writes data to a previously opened file on the host system.

Format

UWRITE var ON FileHandle THEN statement(s) ELSE statement(s)

Description

A file on the host system is represented as an unformatted string of bytes without internal subdividers or markers. Read and write commands provide sequential access to files by advancing a pointer within the file. Subsequent read or write commands advance this internal pointer from the current position in the file. The user can specify the exact location within a file to be written to by positioning the file pointer before executing the command (See ULSEEK Function).

UWRITE allows the user to write the string value of var to a file previously described by FileHandle. FileHandle is obtained from the UOPEN and UCREATE commands. The write starts at the position indicated by the file pointer. The number of contiguous bytes from the current file pointer position to be written is equal to the number of bytes in var. Note that these transfers offer optimal performance in 2000-3000 byte buffers.

Examples

FILENAME="c:\letter\write.txt"

  UOPEN FIELNAME FOR WRITE TO FILEDES2 ELSE

     PRINT "Unable to open ":FILENAME

     STOP

  END

  TESTDATA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

  UWRITE TESTDATA ON FILEDES2 ELSE

     PRINT "Unable to write to ":FILENAME

  END

  UCLOSE FILEDES2 ELSE NULL

The next example displays a file descriptor returned from a UOPEN command being used to write data to a file on the host system. The result is that the alphabet is written to the file \letter\write2.txt. If this file had already existed, the first 26 characters in the file would be overwritten by this command. Other data in the file is not affected.

FILENAME="c:\letter\write2.txt"

  UOPEN FILENAME FOR READWRITE TO FILEDES3 ELSE

     PRINT "Unable to open ":FILENAME

     STOP

  END

  TESTDATA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

  UWRITE TESTDATA ON FILEDES3 ELSE

     PRINT "Unable to write to ":FILENAME

  END

  UCLOSE FILEDES3 ELSE NULL

The following example uses the file descriptor created from the UCREATE command to write data to a file on the host system:

FILENAME="c:\letter\write3.txt"

  UCREATE FILENAME TO FILEDES4 ELSE

     PRINT "Unable to create and open ":FILENAME

     STOP

  END

  TESTDATA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

  UWRITE TESTDATA ON FILEDES4 ELSE

     PRINT "Unable to write to ":FILENAME

  END

  UCLOSE FILEDES4 ELSE NULL

See Also

O/S Interoperability Commands

UCLOSE Command

UCREATE Command

UDELETE Command

UERROR Function

UEXECUTE Command

ULOCK Command

ULSEEK Function

UMESSAGE Command

UOPEN Command

UREAD Command

UREADLINE Function

USYSTEM Function

UWAITFOR Command