Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #17044

RE: subprocess question

Date 2011-12-12 14:49 +0000
From <jyoung79@kc.rr.com>
Subject RE: subprocess question
Newsgroups comp.lang.python
Message-ID <mailman.3546.1323701349.27778.python-list@python.org> (permalink)

Show all headers | View raw


>>>>> 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 comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

RE: subprocess question <jyoung79@kc.rr.com> - 2011-12-12 14:49 +0000

csiph-web