Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #17044 > unrolled thread
| Started by | <jyoung79@kc.rr.com> |
|---|---|
| First post | 2011-12-12 14:49 +0000 |
| Last post | 2011-12-12 14:49 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
RE: subprocess question <jyoung79@kc.rr.com> - 2011-12-12 14:49 +0000
| From | <jyoung79@kc.rr.com> |
|---|---|
| Date | 2011-12-12 14:49 +0000 |
| Subject | RE: subprocess question |
| Message-ID | <mailman.3546.1323701349.27778.python-list@python.org> |
>>>>> import subprocess >>>>> p = subprocess.Popen(['du', '-sh'], cwd='/Users/jay/.Trash/', >> stdout=subprocess.PIPE) >>>>> out, err = p.communicate() >>>>> out >> ' 11M\t.\n' > You might prefer to use subprocess.check_output(); it slightly > simplifies your code: > http://docs.python.org/library/subprocess.html#subprocess.check_output >> And another question - why can't I use the tilde as a shortcut to the home >> directory? > Because ~ is interpolated by the shell and `subprocess` does not use > the shell by default for reasons that include efficiency and security. > You can expand ~ yourself using os.path.expanduser(): > http://docs.python.org/library/os.path.html#os.path.expanduser > Alternatively, you can opt to use the shell by passing shell=True as > an argument. > Cheers, > Chris Thank you very much, Chris and Andrew, for your help. I appreciate it! :-) Jay
Back to top | Article view | comp.lang.python
csiph-web