diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2020-02-25 10:32:44 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-25 10:32:44 -0500 |
commit | f636aa1375fdeafe123b5e6483d5c96da7d3f2ba (patch) | |
tree | 2c3e396b1b022ad6f24ea22773bd03f36cf7ee8e /examples/scripts/conditional.py | |
parent | d25fd7146131688e934290a3c5bf0407e904dbb2 (diff) | |
parent | 5f5c48d51927c27d107b5e9540f5ef867b180145 (diff) | |
download | cmd2-git-f636aa1375fdeafe123b5e6483d5c96da7d3f2ba.tar.gz |
Merge pull request #900 from python-cmd2/bug-898
Updated python scripting exmaple to illustrate how
Diffstat (limited to 'examples/scripts/conditional.py')
-rw-r--r-- | examples/scripts/conditional.py | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/examples/scripts/conditional.py b/examples/scripts/conditional.py index eb4c203e..eb710695 100644 --- a/examples/scripts/conditional.py +++ b/examples/scripts/conditional.py @@ -24,13 +24,20 @@ else: original_dir = os.getcwd() # Try to change to the specified directory -app('cd {}'.format(directory)) +result = app('cd {}'.format(directory)) # Conditionally do something based on the results of the last command -if self.last_result: +if result: + print(f"STDOUT: {result.stdout}\n") + print(f"STDERR: {result.stderr}\n") + print('\nContents of directory {!r}:'.format(directory)) - app('dir -l') - print('{}\n'.format(self.last_result.data)) + result = app('dir -l') + + print(f"STDOUT: {result.stdout}\n") + print(f"STDERR: {result.stderr}\n") + + print('{}\n'.format(result.data)) # Change back to where we were print('Changing back to original directory: {!r}'.format(original_dir)) @@ -38,3 +45,6 @@ if self.last_result: else: # cd command failed, print a warning print('Failed to change directory to {!r}'.format(directory)) + + print(f"STDOUT: {result.stdout}\n") + print(f"STDERR: {result.stderr}\n") |