如何从Windows Batch子例程调用SCons?

时间:2016-06-14 00:07:10

标签: windows batch-file scons

我正在尝试编写一个执行一些SCons命令的.bat文件,但我发现第一次执行后,bash关闭而不执行其他命令。

所以我做了一个子程序并使用CALL命令:

call :my_subroutine
pause
exit /b

:my_subroutine
    scons platform=windows -c
    exit /b

虽然这个子程序在echo "test"里面正确执行,但是一旦我输入scons命令,控制台就说它找不到名为my_subroutine的命令文件......

D:\...\godot>call :my_subroutine

D:\...\godot>scons platform=windows -c
Le système ne trouve pas le nom de fichier de commandes - my_subroutine

D:\...\godot>pause
Appuyez sur une touche pour continuer...

英文消息:

The system doesn't finds the name of the commands file - my_subroutine
[...]
Press a key to continue...

4 个答案:

答案 0 :(得分:0)

尝试使用call scons platform = windows -c

答案 1 :(得分:0)

这种行为是因为它试图跳转到:my_subroutine中的scons.bat子例程的窗口。

可以使用以下一对批处理文件重现这种情况:

<强> test.bat的

rem test.bat :start

call :my_subroutine
exit /b

:my_subroutine
   rem test.bat :my_subroutine
   test2
   exit /b

<强> test2.bat

rem test2.bat :start

exit /b

:my_subroutine
    rem test2.bat :my_subroutine
    echo wtf

产生以下输出:

>test
>rem test.bat :start
>call :my_subroutine
>rem test.bat :my_subroutine
>test2
>rem test2.bat :my_subroutine
>echo wtf
wtf
>exit /b

通话帮助页面说明:

  

CALL命令现在接受标签作为CALL的目标。语法   是:

CALL :label arguments
     

使用指定的参数创建新的批处理文件上下文   控件在指定标签后传递给语句。

即使在调用单独的批处理文件后,似乎仍会继续此行为。

要从您的批处理文件中调用scons.bat绕过此问题,解决方案是(如Guillermo Meza Lopez所说)使用调用:

call scons platform=windows -c

答案 2 :(得分:0)

另一种方法是显式调用python脚本。

python <path to scons.py> platform=windows -c

答案 3 :(得分:0)

找到了如何在此线程中解决此问题的方法:Why does only the first line of this Windows batch file execute but all three lines execute in a command shell?

例如,如果您具有build32.bat和build64.bat,则用于构建所有文件的bat文件应如下所示:

build32.bat & ^
build64.bat

如果要在出现错误的情况下停止运行,请使用&& ^而不是&^。