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."""
23 def chdir(debugger, args, result, dict):
24 """Change the working directory, or cd to ${HOME}.
25 You can also issue 'cd -' to change to the previous working directory."""
26 new_dir = args.strip()
28 new_dir = os.path.expanduser('~')
30 if not Holder.prev_dir():
31 # Bad directory, not changing.
32 print "bad directory, not changing"
35 new_dir = Holder.prev_dir()
37 Holder.swap(os.getcwd())
39 print "Current working directory: %s" % os.getcwd()
42 def system(debugger, command_line, result, dict):
43 """Execute the command (a string) in a subshell."""
44 args = shlex.split(command_line)
45 process = subprocess.Popen(
47 stdout=subprocess.PIPE,
48 stderr=subprocess.PIPE)
49 output, error = process.communicate()
50 retcode = process.poll()
52 print "stdout=>\n", output
53 print "stderr=>\n", error
58 print "retcode:", retcode