17db96d56Sopenharmony_ci:mod:`pipes` --- Interface to shell pipelines 27db96d56Sopenharmony_ci============================================= 37db96d56Sopenharmony_ci 47db96d56Sopenharmony_ci.. module:: pipes 57db96d56Sopenharmony_ci :platform: Unix 67db96d56Sopenharmony_ci :synopsis: A Python interface to Unix shell pipelines. 77db96d56Sopenharmony_ci :deprecated: 87db96d56Sopenharmony_ci 97db96d56Sopenharmony_ci.. sectionauthor:: Moshe Zadka <moshez@zadka.site.co.il> 107db96d56Sopenharmony_ci 117db96d56Sopenharmony_ci**Source code:** :source:`Lib/pipes.py` 127db96d56Sopenharmony_ci 137db96d56Sopenharmony_ci.. deprecated-removed:: 3.11 3.13 147db96d56Sopenharmony_ci The :mod:`pipes` module is deprecated 157db96d56Sopenharmony_ci (see :pep:`PEP 594 <594#pipes>` for details). 167db96d56Sopenharmony_ci Please use the :mod:`subprocess` module instead. 177db96d56Sopenharmony_ci 187db96d56Sopenharmony_ci-------------- 197db96d56Sopenharmony_ci 207db96d56Sopenharmony_ciThe :mod:`pipes` module defines a class to abstract the concept of a *pipeline* 217db96d56Sopenharmony_ci--- a sequence of converters from one file to another. 227db96d56Sopenharmony_ci 237db96d56Sopenharmony_ciBecause the module uses :program:`/bin/sh` command lines, a POSIX or compatible 247db96d56Sopenharmony_cishell for :func:`os.system` and :func:`os.popen` is required. 257db96d56Sopenharmony_ci 267db96d56Sopenharmony_ci.. availability:: Unix, not VxWorks. 277db96d56Sopenharmony_ci 287db96d56Sopenharmony_ciThe :mod:`pipes` module defines the following class: 297db96d56Sopenharmony_ci 307db96d56Sopenharmony_ci 317db96d56Sopenharmony_ci.. class:: Template() 327db96d56Sopenharmony_ci 337db96d56Sopenharmony_ci An abstraction of a pipeline. 347db96d56Sopenharmony_ci 357db96d56Sopenharmony_ciExample:: 367db96d56Sopenharmony_ci 377db96d56Sopenharmony_ci >>> import pipes 387db96d56Sopenharmony_ci >>> t = pipes.Template() 397db96d56Sopenharmony_ci >>> t.append('tr a-z A-Z', '--') 407db96d56Sopenharmony_ci >>> f = t.open('pipefile', 'w') 417db96d56Sopenharmony_ci >>> f.write('hello world') 427db96d56Sopenharmony_ci >>> f.close() 437db96d56Sopenharmony_ci >>> open('pipefile').read() 447db96d56Sopenharmony_ci 'HELLO WORLD' 457db96d56Sopenharmony_ci 467db96d56Sopenharmony_ci 477db96d56Sopenharmony_ci.. _template-objects: 487db96d56Sopenharmony_ci 497db96d56Sopenharmony_ciTemplate Objects 507db96d56Sopenharmony_ci---------------- 517db96d56Sopenharmony_ci 527db96d56Sopenharmony_ciTemplate objects following methods: 537db96d56Sopenharmony_ci 547db96d56Sopenharmony_ci 557db96d56Sopenharmony_ci.. method:: Template.reset() 567db96d56Sopenharmony_ci 577db96d56Sopenharmony_ci Restore a pipeline template to its initial state. 587db96d56Sopenharmony_ci 597db96d56Sopenharmony_ci 607db96d56Sopenharmony_ci.. method:: Template.clone() 617db96d56Sopenharmony_ci 627db96d56Sopenharmony_ci Return a new, equivalent, pipeline template. 637db96d56Sopenharmony_ci 647db96d56Sopenharmony_ci 657db96d56Sopenharmony_ci.. method:: Template.debug(flag) 667db96d56Sopenharmony_ci 677db96d56Sopenharmony_ci If *flag* is true, turn debugging on. Otherwise, turn debugging off. When 687db96d56Sopenharmony_ci debugging is on, commands to be executed are printed, and the shell is given 697db96d56Sopenharmony_ci ``set -x`` command to be more verbose. 707db96d56Sopenharmony_ci 717db96d56Sopenharmony_ci 727db96d56Sopenharmony_ci.. method:: Template.append(cmd, kind) 737db96d56Sopenharmony_ci 747db96d56Sopenharmony_ci Append a new action at the end. The *cmd* variable must be a valid bourne shell 757db96d56Sopenharmony_ci command. The *kind* variable consists of two letters. 767db96d56Sopenharmony_ci 777db96d56Sopenharmony_ci The first letter can be either of ``'-'`` (which means the command reads its 787db96d56Sopenharmony_ci standard input), ``'f'`` (which means the commands reads a given file on the 797db96d56Sopenharmony_ci command line) or ``'.'`` (which means the commands reads no input, and hence 807db96d56Sopenharmony_ci must be first.) 817db96d56Sopenharmony_ci 827db96d56Sopenharmony_ci Similarly, the second letter can be either of ``'-'`` (which means the command 837db96d56Sopenharmony_ci writes to standard output), ``'f'`` (which means the command writes a file on 847db96d56Sopenharmony_ci the command line) or ``'.'`` (which means the command does not write anything, 857db96d56Sopenharmony_ci and hence must be last.) 867db96d56Sopenharmony_ci 877db96d56Sopenharmony_ci 887db96d56Sopenharmony_ci.. method:: Template.prepend(cmd, kind) 897db96d56Sopenharmony_ci 907db96d56Sopenharmony_ci Add a new action at the beginning. See :meth:`append` for explanations of the 917db96d56Sopenharmony_ci arguments. 927db96d56Sopenharmony_ci 937db96d56Sopenharmony_ci 947db96d56Sopenharmony_ci.. method:: Template.open(file, mode) 957db96d56Sopenharmony_ci 967db96d56Sopenharmony_ci Return a file-like object, open to *file*, but read from or written to by the 977db96d56Sopenharmony_ci pipeline. Note that only one of ``'r'``, ``'w'`` may be given. 987db96d56Sopenharmony_ci 997db96d56Sopenharmony_ci 1007db96d56Sopenharmony_ci.. method:: Template.copy(infile, outfile) 1017db96d56Sopenharmony_ci 1027db96d56Sopenharmony_ci Copy *infile* to *outfile* through the pipe. 1037db96d56Sopenharmony_ci 104