Wednesday, November 25, 2009

python: calling a shell command

>>> import subprocess
>>> subprocess.call('ls -l $HOME', shell=True)
total 5608
-rw------- 1 root root     816 2009-10-23 18:51 anaconda-ks.cfg
drwxr-xr-x 3 root root    4096 2009-11-11 21:15 AuthPerformance
drwxr-xr-x 2 root root    4096 2009-11-04 11:34 deleteme
-rw-r--r-- 1 root root     162 2009-10-23 21:08 eth0
-rw-r--r-- 1 root root    4118 2009-10-29 18:03 gdb.txt
-rw-r--r-- 1 root root      99 2009-10-23 21:08 ifcfg-eth0
-rw-r--r-- 1 root root   21859 2009-10-23 18:51 install.log
-rw-r--r-- 1 root root    3155 2009-10-23 18:51 install.log.syslog
-rw-r--r-- 1 root root 1444369 2009-10-26 16:16 libmod_piauth.so
-rw-r--r-- 1 root root 1442766 2009-10-21 18:04 libmod_piauth.so.bkp
drwxr-xr-x 2 root root    4096 2009-11-25 17:49 mozynow
-rw-r--r-- 1 root root  218691 2009-11-19 20:52 pi-auth-2.8-122769-122769-20091119.2030.02-linux-Release.i386.rpm
-rw-r--r-- 1 root root  376900 2009-11-10 11:52 reinstall.log
drwxr-xr-x 5 root root 2146304 2009-11-04 14:28 scripts
-rw-r--r-- 1 root root     382 2009-11-18 18:07 status
-rw-r--r-- 1 root root       0 2009-11-25 17:46 status.1
drwx------ 3 root root    4096 2009-11-19 21:29 usr
0
>>>


source

No comments: