Go to the first, previous, next, last section, table of contents.


Built-in Functions for Input/Output

close(filename)
Close the file filename, for input or output. The argument may alternatively be a shell command that was used for redirecting to or from a pipe; then the pipe is closed. See section Closing Input Files and Pipes, regarding closing input files and pipes. See section Closing Output Files and Pipes, regarding closing output files and pipes.
system(command)
The system function allows the user to execute operating system commands and then return to the awk program. The system function executes the command given by the string command. It returns, as its value, the status returned by the command that was executed. For example, if the following fragment of code is put in your awk program:
END {
     system("mail -s 'awk run done' operator < /dev/null")
}
the system operator will be sent mail when the awk program finishes processing input and begins its end-of-input processing. Note that much the same result can be obtained by redirecting print or printf into a pipe. However, if your awk program is interactive, system is useful for cranking up large self-contained programs, such as a shell or an editor. Some operating systems cannot implement the system function. system causes a fatal error if it is not supported.

Controlling Output Buffering with system

Many utility programs will buffer their output; they save information to be written to a disk file or terminal in memory, until there is enough to be written in one operation. This is often more efficient than writing every little bit of information as soon as it is ready. However, sometimes it is necessary to force a program to flush its buffers; that is, write the information to its destination, even if a buffer is not full. You can do this from your awk program by calling system with a null string as its argument:

system("")   # flush output


Go to the first, previous, next, last section, table of contents.