relpipe-data/examples-cli-stdin.xml
author František Kučera <franta-hg@frantovo.cz>
Sat, 06 Jun 2020 13:22:57 +0200
branchv_0
changeset 300 b9bd0f06b4a1
parent 244 d4f401b5f90c
permissions -rw-r--r--
MySQL seems to works well even with libmyodbc5a.so not only libmyodbc5w.so ODBC driver

<stránka
	xmlns="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/strana"
	xmlns:m="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/makro">
	
	<nadpis>Reading STDIN</nadpis>
	<perex>generating relational data from values on standard input</perex>
	<m:pořadí-příkladu>00200</m:pořadí-příkladu>

	<text xmlns="http://www.w3.org/1999/xhtml">
		
		<p>
			The number of <abbr title="Command-line interface">CLI</abbr> arguments is limited and they are passed at once to the process.
			So there is option to pass the values from STDIN instead of CLI arguments.
			Values on STDIN are expected to be separated by the null-byte.
			We can generate such data e.g. using <code>echo</code> and <code>tr</code> (or using <code>printf</code> or other commands):
		</p>
		
		<m:pre jazyk="bash"><![CDATA[echo -e "1\nHello\ntrue\n2\nWorld\nfalse" \
	| tr \\n \\0 \
	| relpipe-in-cli generate-from-stdin relation_from_stdin 3 \
		a integer \
		b string \
		c boolean \
	| relpipe-out-tabular]]></m:pre>

		<p>
			The output is same as above.
			We can use this approach to convert various formats to relational data.
			There are lot of data already in the form of null-separated values e.g. the process arguments:
		</p>
		
		<m:pre jazyk="bash"><![CDATA[cat /proc/$(pidof mc)/cmdline \
	| relpipe-in-cli generate-from-stdin mc_args 1 a string \
	| relpipe-out-tabular
]]></m:pre>
	
		<p>If we have <code>mc /etc/ /tmp/</code> running in some other terminal, the output will be:</p>
		
		<pre><![CDATA[mc_args:
 ╭────────────╮
 │ a (string) │
 ├────────────┤
 │ mc         │
 │ /etc/      │
 │ /tmp/      │
 ╰────────────╯
Record count: 3]]></pre>

		<p>
			Also the <code>find</code> command can produce data separated by the null-byte:
		</p>
		
		<m:pre jazyk="bash"><![CDATA[find /etc/ -name '*ssh*_*' -print0 \
	| relpipe-in-cli generate-from-stdin files 1 file_name string \
	| relpipe-out-tabular]]></m:pre>
	
		<p>Will display something like this:</p>
		
		<pre><![CDATA[files:
 ╭───────────────────────────────────╮
 │ file_name                (string) │
 ├───────────────────────────────────┤
 │ /etc/ssh/ssh_host_ecdsa_key       │
 │ /etc/ssh/sshd_config              │
 │ /etc/ssh/ssh_host_ed25519_key.pub │
 │ /etc/ssh/ssh_host_ecdsa_key.pub   │
 │ /etc/ssh/ssh_host_rsa_key         │
 │ /etc/ssh/ssh_config               │
 │ /etc/ssh/ssh_host_ed25519_key     │
 │ /etc/ssh/ssh_import_id            │
 │ /etc/ssh/ssh_host_rsa_key.pub     │
 ╰───────────────────────────────────╯
Record count: 9]]></pre>
		
	</text>

</stránka>