blob: 27836f62e1ca499f1bec66fb17eafa4e3c26e084 [file] [log] [blame]
Johnny Chende6ade02011-10-12 19:16:06 +00001"""Utility for changing directories and execution of commands in a subshell."""
2
3import os, shlex, subprocess
4
5def chdir(debugger, args, result, dict):
6 """Change the working directory, or cd to ${HOME}."""
7 dir = args.strip()
8 if dir:
9 os.chdir(args)
10 else:
11 os.chdir(os.path.expanduser('~'))
12 print "Current working directory: %s" % os.getcwd()
13
14def system(debugger, command_line, result, dict):
15 """Execute the command (a string) in a subshell."""
16 args = shlex.split(command_line)
17 process = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
18 output, error = process.communicate()
19 retcode = process.poll()
20 if output and error:
21 print "stdout=>\n", output
22 print "stderr=>\n", error
23 elif output:
24 print output
25 elif error:
26 print error
27 print "retcode:", retcode