blob: 3964ab6dcdeb539ba8f270154bbee4aaec78aad8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# coding=utf-8
"""
This is a Python script intended to be used with the "python_scripting.py" cmd2 example application.
To run it you should do the following:
./python_scripting.py
py run('script_conditional.py')
Note: The "cmd" function is defined within the cmd2 embedded Python environment and in there "self" is your cmd2
application instance.
"""
# Try to change to a non-existent directory
cmd('cd foobar')
# Conditionally do something based on the results of the last command
if self._last_result:
print('Contents of foobar directory:')
cmd('dir')
else:
# Change to parent directory
cmd('cd ..')
print('Contents of parent directory:')
cmd('dir')
|