从摊铺机任务中执行 .bat 文件

Execute .bat file from within paver task

如何在使用 python 模块 paver 定义的任务中执行批处理文件?我是否必须区分摊铺机任务将在哪个操作系统 (unix/windows) 上执行?

例如在项目根目录的 pavement.py 中定义的以下任务执行所有单元测试(使用 python 标准库模块 unittest[=56 定义=]) 在项目中定义

from paver.tasks import task
from paver.easy import sh

@task
def unit_tests():
"""
Run all unit tests.
"""
    sh('python -m unittest')

如果有人执行

paver unit_tests

从项目根目录中的命令行。

但是我无法在 windows 操作系统(位于项目根目录)上使用

执行批处理文件
sh('batchfile.bat')

我也无法使用 cwd[= 在项目根目录的子目录 venv/Scripts 中执行批处理文件56=] sh() [paver source code] 的参数,具有以下选项之一

# no call does execute the batch file (*cwd* alternatives)
sh('batchfile.bat', cwd='venv/Scripts')
sh('cmd /c batchfile.bat', cwd='venv/Scripts')

# no call does execute the batch file (*sh()* "sequential command" syntax alternatives)
sh('cd venv/Scripts; deactivate.bat')
sh('cd venv/Scripts; cmd /c deactivate.bat')

# this sequence does also not execute the batch file (absolute path alternative)
path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'venv\Scripts')
sh('deactivate.bat', cwd=path)

编辑:

我在根目录和子目录venv/Scripts/:[=中创建了一个与"virtualenv processing"无关的批处理文件hello_world.bat 21=]

@echo off
echo hello world
pause

通话中

paver root_dir_call

paver sub_dir_call

windows上的项目根目录中添加pavement.py中的摊铺机任务执行批处理文件,do execute the batch file with side effects 或不执行依赖于特定未注释的 sh() 命令的批处理文件:

@task
def root_dir_call():
    # use one of these two calls!
    sh('hello_world.bat') # PASS
    #sh('hello_world') # PASS

    # do not use other calls like these two because they have side effects or do not execute the batch file at all
    #sh('call hello_world.bat') # PASS (execution with side effects)
    #sh('cmd /c hello_world.bat') # PASS (execution with side effects)
    #sh('start hello_world.bat') # PASS (execution with side effects)
    #sh('cmd hello_world.bat') # FAIL (no execution, output of cmd!?)

@task
def sub_dir_call():
    # use one of these calls!
    sh('hello_world.bat', cwd='venv/Scripts/') # PASS
    #sh('hello_world', cwd='venv/Scripts') # PASS
    #sh('hello_world', cwd='venv\Scripts') # PASS

    # following calls do not execute the batch file
    #sh('cd venv/Scripts; hello_world.bat') # FAIL
    #sh('cd venv/Scripts/; hello_world.bat') # FAIL
    #sh('cd venv\Scripts\; hello_world.bat') # FAIL
    #sh('cd venv/Scripts; cmd /c hello_world.bat') # FAIL

似乎当前版本的摊铺机有一个bug related to the virtualenv support on windows systems see this issue