stdio 3plumb 2012-08-12

NAME

stdio - plumb library

SYNPOSIS

include stdio

stdin:*, stdout:*, stderr:*

STDIN:*, STDOUT:*, STDERR:*

$LSP

DESCRIPTION

Stdio will provide six [hub] processes called in two sets. Members of the first set is called stdin, stdout and stderr and are connected to env:0, env:1 and env:2 without eof-filtering - if any of the connected processes or the env:* fd delivers an eof, they distribute the eof. The other set has STDIN, STDOUT and STDERR, which are connected to the corresponding lowercase counterpart, and are set to ignore eof.

In practice this means processes that should not receive eof on input shall be connected to STDIN, processes which should not cause output env fd to close shall be connected to STDOUT or STDERR.

$LSP creates a new linesplit object and is a shorthand for ensuring each record is a line with a single newline character at the end. Commonly used on the output of real processes.

EXAMPLE

Copy all input to stdout and stderr, quit when read eof on stdin:
	stdin:* | [hub],sticky=1 | stdout:*
	stdin:* | [hub],sticky=1 | stderr:*

Insert timer marks in the output of an awk filter script for benchmarking purposes:

	stdin:* | {awk -f filter1.awk} | $LSP | stdout:*
	[timer repeat=0 period=0.1] | stdout:*

Run multiple scripts writing stdout and reading stdin with different exit strategies, for 60 seconds:

	# keep running animator as long as the script is running,
	# even if stdin got eof
	STDIN:* | {animator},sticky=0

	# debug script; close stdout when stdin ran out
	stdin:* | {awk -f filter1.awk} | $LSP | stdout:*

	# print 5 timer messages to stdout but do not close
	# stdout when the timer is over
	[timer count=5 period=0.1] | STDOUT:*

	# do not exit even if stdin and/or stdout are both closed,
	# unless at least 60 seconds passed since startup
	[timer count=1 period=60],sticky=1

SEE ALSO

stdio 3plumb 2012-08-12