2

I am trying to write a .bat file that executes a few SCons commands, but I found that once the first executes, the bash closes without executing the others.

So I made a sub-routine and use the CALL command:

call :my_subroutine
pause
exit /b

:my_subroutine
    scons platform=windows -c
    exit /b

While this subroutine executes correctly with a echo "test" inside, as soon as I put the scons command, the console says it can't find the command file named 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...

Messages in english:

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

4 Answers4

0

Try using call scons platform=windows -c

  • 1
    Hint: You can format code as code by enclosing it in `\`\`` or by indenting it with four spaces to make your post more readable. – Baum mit Augen Oct 19 '16 at 00:51
0

This behaviour is because windows it trying to skip to a :my_subroutine subroutine in scons.bat.

The situation can be reproduced with the following pair of batch files:

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

That produce the following output:

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

The call help page states:

CALL command now accepts labels as the target of the CALL. The syntax is:

CALL :label arguments

A new batch file context is created with the specified arguments and control is passed to the statement after the label specified.

It appears that this behaviour continues even after invoking a separate batch file.


To invoke scons.bat from your batch file bypassing this gotcha the solution is (as Guillermo Meza Lopez says) to use call:

call scons platform=windows -c
Kelly Thomas
  • 440
  • 7
  • 17
0

Another way to make this work is to explicitly call the python script.

python <path to scons.py> platform=windows -c
bdbaddog
  • 3,357
  • 2
  • 22
  • 33
0

Found how to fix this in this thread : Why does only the first line of this Windows batch file execute but all three lines execute in a command shell?

For instance if you have build32.bat and build64.bat, your bat file to build all should look like this :

build32.bat & ^
build64.bat

If you want to stop running in case of error, use && ^ instead of & ^.

Sungray
  • 41
  • 2