File: stdin.rst

package info (click to toggle)
python-sh 2.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 900 kB
  • sloc: python: 4,157; makefile: 25
file content (29 lines) | stat: -rw-r--r-- 667 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
.. _stdin:

Input via STDIN
===============

STDIN is sent to a process directly by using a command's :ref:`in` special
kwarg:

.. code-block:: python

	print(cat(_in="test"))
	
Any command that takes input from STDIN can be used this way:

.. code-block:: python

	print(tr("[:lower:]", "[:upper:]", _in="sh is awesome"))
	
You're also not limited to using just strings.  You may use a file object, a
:class:`queue.Queue`, or any iterable (list, set, dictionary, etc):

.. code-block:: python

	stdin = ["sh", "is", "awesome"]
	out = tr("[:lower:]", "[:upper:]", _in=stdin)

.. note::

    If you use a queue, you can signal the end of the queue (EOF) with ``None``