1 """Utility for changing directories and execution of commands in a subshell."""
7 # Store the previous working directory for the 'cd -' command.
11 """Holds the _prev_dir_ class attribute for chdir() function."""
24 def chdir(debugger
, args
, result
, dict):
25 """Change the working directory, or cd to ${HOME}.
26 You can also issue 'cd -' to change to the previous working directory."""
27 new_dir
= args
.strip()
29 new_dir
= os
.path
.expanduser("~")
31 if not Holder
.prev_dir():
32 # Bad directory, not changing.
33 print("bad directory, not changing")
36 new_dir
= Holder
.prev_dir()
38 Holder
.swap(os
.getcwd())
40 print("Current working directory: %s" % os
.getcwd())
43 def system(debugger
, command_line
, result
, dict):
44 """Execute the command (a string) in a subshell."""
45 args
= shlex
.split(command_line
)
46 process
= subprocess
.Popen(args
, stdout
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
)
47 output
, error
= process
.communicate()
48 retcode
= process
.poll()
50 print("stdout=>\n", output
)
51 print("stderr=>\n", error
)
56 print("retcode:", retcode
)