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 may specify the exact location within a file to be written to by positioning the file pointer at the preferred location before executing the command.

See the ulseek() function section for more information.

The uwrite command allows the user to write the string value of var to a file previously described by the FileHandle variable. The FileHandle variable is obtained from the uopen command and the ucreate command. 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 variable.

Note: These transfers offer optimal performance in 2000-3000 byte buffers.

Example(s)

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 following 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 \letter\write2.txt file. 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