I recently inherited a project with some simply .bat files for building it. However, I would like to run those files from within WSL. In particular, it has two build files it uses in a nested fashion.
build.bat:
call generated_java.bat mvn clean compiler assembly:singlegenerate_java.bat:
SET path_to_grammar=%~dp0\resources SET path_to_package=%~dp0\src\main\java\xyzzy SET path_to_antlr=%~dp0\bin\antlr-4.8-complete.jar echo %path_to_grammar% echo %path_to_package% echo %path_to_antlr% @java -Xmx500M -jar %path_to_antlr% -o %path_to_package% -Dlanguage=Java -package xyzzy -encoding UTF-8 -listener -visitor %path_to_grammar%\Lexer.g4 %path_to_grammar%\Parser.g4I run it from WSL by typing:
command ./build.bat | catHowever, it gives me error messages like:
@echo: command not found SET: command not found ... @java: command not foundWhich seems like it is treating the called generate_files.bat like a bash shell script and not a .bat file it should run with command.
Any suggestions on how to fix this and still do this from inside WSL and not running a DOS box (or whatever they call the command terminal these days). I care because I want to run this inside my Emacs which I start up under WSL and use for all my shell'ing because it captures all output in an scrollable and editable buffer.
3 Answers
If you want to start cmd.exe from wsl to run a batch, you have to call it properly and give it the correct path to the batch. It would be easiest if the batch was in a folder on the Windows file system
This is how I run a batch script from wsl2 using 32 bit cmd.exe
/mnt/c/Windows/SysWOW64/cmd.exe /c c:\batch\wslxvnc.bat
If you need 64 bit cmd.exe use /mnt/c/Windows/System32/cmd.exe
The key is to type:
cmd.exe /c built.batcmd and command are treated as Linux commands. You need the .exe suffix to get the "Windows command prompt".
command is a shell builtin. From (man bash):
command [-pVv] command [arg ...] Run command with args suppressing the normal shell function lookup. Only builtin commands or commands found in the PATH are executed. If the -p option is given, the search for command is performed using a default value for PATH that is guaranteed to find all of the standard utilities. If either the -V or -v option is supplied, a description of command is printed. The -v option causes a single word indicating the command or file name used to invoke command to be displayed; the -V option produces a more verbose description. If the -V or -v option is supplied, the exit status is 0 if command was found, and 1 if not. If neither option is supplied and an error occurred or command cannot be found, the exit status is 127. Otherwise, the exit status of the command builtin is the exit status of command. So, it will fail if you use it. I can easily run them using:
cmd.exe /c build.bat 2