The least scripting language part of Python is that you have to do ʻimport subprocess; subprocess.call ("ls -l ")
`to execute an external command, which is annoying.
Paver defines a sh ()
function that makes it easier to execute external commands. This can also be imported with from paver.easy import *
.
If you write sh ("ls -l /")
, the command will be executed via the shell.
By default, the output of the executed command is displayed as it is in the standard output, but if you specify capture = True
,
pavement.py
from paver.easy import *
import os
@task
def list():
ret = sh("ls -l /", capture=True)
print(len(ret.splitlines()))
$ paver list
---> pavement.list
ls -l /
22
dryrun
Like the methods of the path
class, the sh ()
function only displays the command and does not actually execute it when paver is run in dryrun mode.
pavement.py
from paver.easy import *
@task
def barusu():
sh("rm -rf /")
$ paver -n barusu
---> pavement.barusu
rm -rf /