Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.mixmin.net!eweka.nl!hq-usenetpeers.eweka.nl!xlned.com!feeder3.xlned.com!amsnews11.chello.com!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'admit': 0.09; 'module?': 0.09; 'shortcut': 0.09; 'subprocess': 0.09; '[errno': 0.16; '__init__': 0.16; 'err': 0.16; 'errread,': 0.16; 'oserror:': 0.16; 'shed': 0.16; 'skip:" 80': 0.16; 'subject:subprocess': 0.16; 'trash': 0.16; 'x),': 0.16; 'subject:question': 0.17; '>>>': 0.18; 'this?': 0.19; '(most': 0.21; '(on': 0.23; 'traceback': 0.24; "i'm": 0.26; 'import': 0.27; 'raise': 0.28; 'received:10.127': 0.30; 'received:75.180': 0.30; 'received:75.180.132': 0.30; 'received:cdptpa-omtalb.mail.rr.com': 0.30; 'thanks': 0.31; 'anyone': 0.31; "i've": 0.31; "i'll": 0.31; 'wanting': 0.32; 'wondering': 0.32; "can't": 0.32; 'to:addr:python-list': 0.34; 'last):': 0.34; 'received:mail.rr.com': 0.34; 'light': 0.35; 'test': 0.35; 'however,': 0.36; 'file': 0.36; 'questions.': 0.36; 'question': 0.36; 'but': 0.37; 'received:75': 0.37; 'another': 0.37; 'skip:_ 10': 0.37; 'could': 0.37; 'some': 0.38; 'received:rr.com': 0.39; 'why': 0.39; "it's": 0.40; 'to:addr:python.org': 0.40; 'from:no real name:2**0': 0.63; 'home': 0.65 Authentication-Results: cdptpa-omtalb.mail.rr.com smtp.user=jyoung79@kc.rr.com; auth=pass (LOGIN) X-Authority-Analysis: v=2.0 cv=KapQQHkD c=1 sm=0 a=IkcTkHD0fZMA:10 a=k5firICUa-dMn5FgnqoA:9 a=bAHYOoF98CHqvLHRGRUA:7 a=QEXdDO2ut3YA:10 a=M9wi1zWtvKmOCzV4vqnM4A==:117 X-Cloudmark-Score: 0 Date: Mon, 12 Dec 2011 4:39:33 +0000 From: To: python-list@python.org Subject: subprocess question MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) Sensitivity: Normal X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1323664783 news.xs4all.nl 6977 [2001:888:2000:d::a6]:35100 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:17008 Wondering if anyone could shed some light on the subprocess module? I'll admit I'm not that great at the shell. If I was wanting to get the size of the trash (on OS X), I could use: >>> os.system('du -sh ~/.Trash/') 11M /Users/jay/.Trash/ 0 Which gives me what I want. However, I've been reading that it's better to use subprocess. I did a test like so, but is this a good way to do this? >>> import subprocess >>> p = subprocess.Popen(['du', '-sh'], cwd='/Users/jay/.Trash/', stdout=subprocess.PIPE) >>> out, err = p.communicate() >>> out ' 11M\t.\n' >>> err >>> And another question - why can't I use the tilde as a shortcut to the home directory? >>> p = subprocess.Popen(['du', '-sh'], cwd='~/.Trash/', stdout=subprocess.PIPE) Traceback (most recent call last): File "", line 1, in File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 672, in __init__ errread, errwrite) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1202, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory: '~/.Trash/' Thanks for looking at my questions. Jay