Top
Systemwalker Operation Manager  Reference Guide
FUJITSU Software

15.2.14 open (Open a File)

Description

Opens a file.

Synopsis

open filename [access]

Options

filename

Specify the name of a file to open. The file names on Windows can be also separated by a slash (/) in addition to the backslash sign (\). When using a backslash sign, the entire file name must be enclosed in braces ({}) so as not to be treated as an escape character. If the filename contains spaces or tabs, it must be enclosed in double quotations ("").

access

Specify the access mode. When omitted, it defaults to read-only (r) access. The values to specify access are as follows:

Types of access modes

Code

Description

r

Opens the file in read-only mode (default value). The file must already exist.

r+

Opens the file in read-and-write mode. The file must already exist.

w

Opens the file in write-only mode. Overwrites the file if exists. If it does not exist, creates a new file.

w+

Opens the file in read-and-write mode. Overwrites the file if exists. If it does not exist, creates a new file.

a

Opens the file in write-only mode. The file must already exist. The write data is added to the end of the file.

a+

Opens the file in read-and-write mode. If the file does not exist, creates a new file. The write data is added to the end of the file.

Return Value

Channel ID:

Since the channel ID must be specified to access an open file (including its closing), the return value needs to be stored in the variable through command substitution.

Reference

close

Caution

If the script fails to open a file (e.g. if a file with no permissions assigned is specified), it is forced to exit upon detecting the occurrence of an exception. When using this command, trap exceptions using the catch command where necessary.

Examples

[Windows]

The following example opens the c:\tmp\data file in write-only mode and stores its channel ID in variable fc.

set fc [open {c:\tmp\data} w]

[UNIX]

The following example opens the /var/tmp/data file in write-only mode and stores its channel ID in variable fc.

set fc [open /var/tmp/data w]