Coprocesses and Sockets
gawk allows you to open a
two-way pipe to another process, called a
coprocess. This is done with the |& operator used with getline and print or printf.
print database command |& "db_server"
"db_server" |& getline responseIf the command used with |& is a filename beginning with
/inet/, gawk opens a TCP/IP connection. The
filename should be of the following form:
/inet/protocol/lport/hostname/rport
The parts of the filename are:
- protocol
One of
tcp,udp, orraw, for TCP, UDP, or raw IP sockets, respectively. Note:rawis currently reserved but unsupported.- lport
The local TCP or UPD port number to use. Use
0to let the operating system pick a port.- hostname
The name or IP address of the remote host to connect to.
- rport
The port (application) on the remote host to connect to. A service name (e.g.,
tftp) is looked up using the Cgetservbyname()function.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access