Search code examples
batch-filecmdbazel

Bazel run action via .bat file shows warning and shuts down


I run my bazel C++ project successfully with custom argument using the following command in powershell/cmd

start bazel run -c opt main -- --players="5"

but when I try to run the same command using a custom .bat file

echo off
start cmd /k CD C:\Users\user\Documents\Code\game
start bazel run -c opt main -- --players="5"

new cmd window pops up with the error/warning is as follows before this cmd window shuts down

G: Invoking Bazel in batch mode since it is not invoked from within a workspace (below a directory having a WORKSPACE file). OpenJDK 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release.

EDIT: Thanks to user: compo, I was able to build the program using the .bat file but cmd window doesn't seem to stay open for far too long. Following are the changes I've tried so far. None of them seem to keep the window open for longer than program finishes building and briefly launching before the cmd window abruptly closing right after.

@START /REALTIME /WAIT /B /D "%UserProfile%\Documents\Code\game" bazel run -c opt main -- --players="5"

@CD /D "%UserProfile%\Documents\Code\game" 2>NUL && bazel run -c opt main -- --players="5"

Solution

  • set /p= worked for me, to be used at the end of the command. It will expect user input and will release the flow when enter is pressed. In my case:

    @START /B /D "%UserProfile%\Documents\Code\game" bazel run -c opt main -- --players="5"
    
    set /p=