relpipe-data/examples-cli-stdin.xml
branchv_0
changeset 244 d4f401b5f90c
parent 241 f71d300205b7
equal deleted inserted replaced
243:9c1d0c5ed599 244:d4f401b5f90c
       
     1 <stránka
       
     2 	xmlns="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/strana"
       
     3 	xmlns:m="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/makro">
       
     4 	
       
     5 	<nadpis>Reading STDIN</nadpis>
       
     6 	<perex>generating relational data from values on standard input</perex>
       
     7 	<m:pořadí-příkladu>00200</m:pořadí-příkladu>
       
     8 
       
     9 	<text xmlns="http://www.w3.org/1999/xhtml">
       
    10 		
       
    11 		<p>
       
    12 			The number of <abbr title="Command-line interface">CLI</abbr> arguments is limited and they are passed at once to the process.
       
    13 			So there is option to pass the values from STDIN instead of CLI arguments.
       
    14 			Values on STDIN are expected to be separated by the null-byte.
       
    15 			We can generate such data e.g. using <code>echo</code> and <code>tr</code> (or using <code>printf</code> or other commands):
       
    16 		</p>
       
    17 		
       
    18 		<m:pre jazyk="bash"><![CDATA[echo -e "1\nHello\ntrue\n2\nWorld\nfalse" \
       
    19 	| tr \\n \\0 \
       
    20 	| relpipe-in-cli generate-from-stdin relation_from_stdin 3 \
       
    21 		a integer \
       
    22 		b string \
       
    23 		c boolean \
       
    24 	| relpipe-out-tabular]]></m:pre>
       
    25 
       
    26 		<p>
       
    27 			The output is same as above.
       
    28 			We can use this approach to convert various formats to relational data.
       
    29 			There are lot of data already in the form of null-separated values e.g. the process arguments:
       
    30 		</p>
       
    31 		
       
    32 		<m:pre jazyk="bash"><![CDATA[cat /proc/$(pidof mc)/cmdline \
       
    33 	| relpipe-in-cli generate-from-stdin mc_args 1 a string \
       
    34 	| relpipe-out-tabular
       
    35 ]]></m:pre>
       
    36 	
       
    37 		<p>If we have <code>mc /etc/ /tmp/</code> running in some other terminal, the output will be:</p>
       
    38 		
       
    39 		<pre><![CDATA[mc_args:
       
    40  ╭────────────╮
       
    41  │ a (string) │
       
    42  ├────────────┤
       
    43  │ mc         │
       
    44  │ /etc/      │
       
    45  │ /tmp/      │
       
    46  ╰────────────╯
       
    47 Record count: 3]]></pre>
       
    48 
       
    49 		<p>
       
    50 			Also the <code>find</code> command can produce data separated by the null-byte:
       
    51 		</p>
       
    52 		
       
    53 		<m:pre jazyk="bash"><![CDATA[find /etc/ -name '*ssh*_*' -print0 \
       
    54 	| relpipe-in-cli generate-from-stdin files 1 file_name string \
       
    55 	| relpipe-out-tabular]]></m:pre>
       
    56 	
       
    57 		<p>Will display something like this:</p>
       
    58 		
       
    59 		<pre><![CDATA[files:
       
    60  ╭───────────────────────────────────╮
       
    61  │ file_name                (string) │
       
    62  ├───────────────────────────────────┤
       
    63  │ /etc/ssh/ssh_host_ecdsa_key       │
       
    64  │ /etc/ssh/sshd_config              │
       
    65  │ /etc/ssh/ssh_host_ed25519_key.pub │
       
    66  │ /etc/ssh/ssh_host_ecdsa_key.pub   │
       
    67  │ /etc/ssh/ssh_host_rsa_key         │
       
    68  │ /etc/ssh/ssh_config               │
       
    69  │ /etc/ssh/ssh_host_ed25519_key     │
       
    70  │ /etc/ssh/ssh_import_id            │
       
    71  │ /etc/ssh/ssh_host_rsa_key.pub     │
       
    72  ╰───────────────────────────────────╯
       
    73 Record count: 9]]></pre>
       
    74 		
       
    75 	</text>
       
    76 
       
    77 </stránka>