Tcl puts options

By: e-lena Date: 18.07.2017

In this chapter, we will work with input and output operations in Tcl. Tcl has several commands for doing io. We will cover a few of them. Tcl uses objects called channels to read and write data.

The channels can be created using the open or socket command.

tcl puts options

There are three standard channels available to Tcl scripts without explicitly creating them. They are automatically opened by the OS for each new application. They are stdin , stdout and stderr. The standard input, stdin , is used by the scripts to read data.

The standard output, stdout , is used by scripts to write data. The standard error, stderr , is used by scripts to write error messages. In the first example, we will work with the puts command. It has the following synopsis:. The channelId is the channel where we want to write text. The channelId is optional. If not specified, the default stdout is assumed. This line does the same thing as the previous one.

We only have explicitly specified the channelId. The read command is used to read data from a channel.

Tcl and Tk Programming for the Absolute Beginner - Kurt Wall - Google Livres

The optional argument specifies the number of characters to read. If omitted, the command reads all of the data from the channel up to the end. The script reads a character from the standard input channel and then writes it to the standard output until it encounters the q character. The gets command reads the next line from the channel, returns everything in the line up to but not including the end-of-line character. The puts command is used to print messages to the terminal.

The -nonewline option supresses the new line character.

Tcl buffers output internally, so characters written with puts may not appear immediately on the output file or device. The flush command forces the output to appear immediately. Tcl has pwd and cd commands, similar to shell commands. The pwd command returns the current working directory and the cd command is used to change the working directory.

In this script, we will print the current working directory.

tcl puts options

Then we change the working directory and print the working directory again. We change the working directory to the parent of the current directory. We use the cd command. The file volumes command returns the absolute paths to the volumes mounted on the system.

JANUS 3 Documentation

On a Linux system, there is one mounted volume—the root directory. The ls command confirms the creation of the new directory. In the following code example, we are going to check if a file name is a regular file or a directory.

TCL/TK format force width - Tcl/Tk - Tek-Tips

We go through all file names in the current working directory and print whether it is a file or a directory. Using the glob command we create a list of file and directory names of a current directory. The file isdirectory command determines, whether a file name is a directory.

Note that on Unix, a directory is a special case of a file. We open a file named days for writing. The open command returns a channel id. If we do not provide a second parameter to the read command, it reads all data from the file until the end of the file. The loop continues until the eof returns true if it encounters the end of a file.

tcl puts options

Inside the body, we use the gets command to read a line from the file. We open a file and write some text to it.

The file is copied. The original file is then deleted. The script creates two columns. In the first column, we have the name of the file. In the second column, we display the size of the file. In this loop, we find out the most lengthy file name. This will be used when formatting the output columns. Here we print the headers of the columns.

To format the data, we use the format command. We go through the list of files and print each file name and its size. The file size command determines the size of the file. Home Contents Subscribe Previous.

inserted by FC2 system