Previous Page Next Page Contents

read -- search, read, and execute a file

Introduction

read(filename) searches for the file filename in certain directories, reads and executes it.

read(n) reads and executes the file associated with the file descriptor n.

Call(s)

read(filename <, Quiet> <, Plain>)
read(n <, Quiet> <, Plain>)

Parameters

filename - the name of a file: a character string
n - a file descriptor provided by fopen: a positive integer

Options

Plain - makes read use its own parser context
Quiet - suppresses output during execution of read

Returns

the return value of the last statement of the file.

Related Functions

fclose, finput, fopen, fprint, fread, ftextinput, input, LIBPATH, loadproc, pathname, print, protocol, READPATH, textinput, write, WRITEPATH

Details

Example 1

The following example only works under UNIX and Linux; on other operating systems one must change the path names accordingly. First, we use write to store values in the file ``testfile.mb'' in the ``/tmp'' directory:

>> a := 3: b := 5: write("/tmp/testfile.mb", a, b):

The following command specifies the file by its absolute path name. After reading the file, the values of a and b are restored:

>> delete a, b: read("/tmp/testfile.mb"): a, b
                                   3, 5

Alternatively, we define ``/tmp'' as the search directory and provide a relative path name. Note that the path separator ``/'' is inserted by read:

>> delete a, b: READPATH := "/tmp": read("testfile.mb"): a, b
                                   3, 5

We may also use fopen to open the file and read its content. Note that fopen does not search for the file like read, thus we must enter an absolute path name or a name relative to the working directory:

>> delete a, b:
   n := fopen("/tmp/testfile.mb"): read(n): fclose(n):
   a, b
                                   3, 5
>> delete a, b, READPATH, n

Changes




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000