summaryrefslogtreecommitdiff
path: root/docs/features/generating_output.rst
diff options
context:
space:
mode:
authorkotfu <kotfu@kotfu.net>2019-07-16 09:45:42 -0600
committerGitHub <noreply@github.com>2019-07-16 09:45:42 -0600
commiteb882b2b308bb2e09761a74007ea308b489c2d56 (patch)
treedabbaf6aa290e57c7140e4b1d32f1cd1f38bcaac /docs/features/generating_output.rst
parent94b424e9c41f99c6eb268c6c97f09e99a8342de8 (diff)
parentd68f6893396109afa0c7ca4ecfe72ecf192cfc0d (diff)
downloadcmd2-git-eb882b2b308bb2e09761a74007ea308b489c2d56.tar.gz
Merge pull request #720 from python-cmd2/migrating_docs
Write documentation for migrating from cmd
Diffstat (limited to 'docs/features/generating_output.rst')
-rw-r--r--docs/features/generating_output.rst33
1 files changed, 33 insertions, 0 deletions
diff --git a/docs/features/generating_output.rst b/docs/features/generating_output.rst
index 1dab6f64..5813322b 100644
--- a/docs/features/generating_output.rst
+++ b/docs/features/generating_output.rst
@@ -9,4 +9,37 @@ how to generate output
- exceptions
- color support
+Output Redirection
+------------------
+
+As in a Unix shell, output of a command can be redirected:
+
+ - sent to a file with ``>``, as in ``mycommand args > filename.txt``
+ - appended to a file with ``>>``, as in ``mycommand args >> filename.txt``
+ - piped (``|``) as input to operating-system commands, as in
+ ``mycommand args | wc``
+
+
+
+.. note::
+
+ If you wish to disable cmd2's output redirection and pipes features, you can
+ do so by setting the ``allow_redirection`` attribute of your ``cmd2.Cmd``
+ class instance to ``False``. This would be useful, for example, if you want
+ to restrict the ability for an end user to write to disk or interact with
+ shell commands for security reasons::
+
+ from cmd2 import Cmd
+ class App(Cmd):
+ def __init__(self):
+ self.allow_redirection = False
+
+ cmd2's parser will still treat the ``>``, ``>>``, and `|` symbols as output
+ redirection and pipe symbols and will strip arguments after them from the
+ command line arguments accordingly. But output from a command will not be
+ redirected to a file or piped to a shell command.
+
+If you need to include any of these redirection characters in your command, you
+can enclose them in quotation marks, ``mycommand 'with > in the argument'``.
+