open 3plumb | 2012-09-04 |
---|
open - open a file for reading and/or writing
[open FILENAME]
3 (control) | V +------+ 0 (stdin) ---->| open |---> (stdout) 1 +------+ | V (stderr) 2
Open file FILENAME for reading and writing, depending on presnce of pipe on stdin and stdout. After opening the file for reading (stdout bound), plumb will non-blocking read its content until (including) eof and close stdout. If a file is (also) open for writing (stdin bound), plumb will read stdin until eof and copy everything into the file.NOTE: Whether the file was open for reading or writing or both can not be changed after startup - [hub] can be used as a placeholder to create a pipe on stdin and/or stdout and attach processes in a later transaction
eof handling
Default.blocking/flow control
Default.buffering
None.control
TODO. Current version ignores control; plans for controls in later versions: seek, rotate, close
The following example loads a config file and injects it in the stdin stream of an awk script. This simplifies the awk script as it doesn't need to open and load the file with a loop, however may cause a race condition as reading the file and stdin is parallel and some stdin lines may arrive before config lines:script=[hub] | {awk -f ai.awk} env:0 | [affix prefix="STDIN "] | script:* [open default.conf] | [affix prefix="CFG "] | script:*Log all output of a script:
script={awk -f ai.awk} | sc_out=[hub] | env:1 sc_out:* | [open stdout.log]Run the script on stdio and /dev/ttyS0 for controlling a serial device:
# script: sc_in=[hub] | {awk -f ai.awk} | sc_out=[hub] # handle stdio: sc_out:* | [regex pattern="^OUT: "] | env:1 env:0 | [affix prefix="IN: "] " sc_in:* # handle the serial line: sc_out:* | [regex pattern="^SERIAL: "] | [open /dev/ttyS0] | [regex pattern="^SERIAL: "] | sc_in:*
open 3plumb | 2012-09-04 |
---|