I'm new to batch, but I figured out it would be a good way to compile the .less files for my website into .css before deploying it.
Unfortunately, after I use a for loop in a batch file to find all of my .less files and compile them into their .css equivalents, my script stops execution even though I have more commands after the for loop.
My batch script contains the following:
@echo off
rmdir c:\code\releaseDirectory /s /q
echo d | xcopy /d c:\code\devDirectory c:\code\releaseDirectory /s
cd c:\code\releaseDirectory
for /r %%i in (*.less) do echo %%i
for /r %%i in (*.less) do lessc -x %%i > %%~pi%%~ni.css
echo reached the end of the batch script!
When I run this, the output shows all of the .less compiling happening, but the "reached the end of the batch script!" string never get displayed and thus, and any actions I want to take after the .less compilation never happen.
Why isn't any script after the less compilation in the for loop being executed?
I had this same issue and had to change lessc to call lessc and then my script stopped ending prematurely. Here is a SO link that lead me to try it: Why does calling a nested batch file without prepending "call" to the line exit the parent batch file? Basically it says that you need to use call when executing nested batch files so that control will be returned to the parent file when the sub-file is finished executing.
Is there a lessc.bat in your path?
If so, you need to CALL lessc...
Perhaps ...do ECHO %%i& lessc -x %%i > %%~pi%%~ni.css
may reveal more...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With