Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.less compilation in batch for-loop ends batch script prematurely

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?

like image 559
James J Avatar asked Dec 30 '25 13:12

James J


2 Answers

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.

like image 71
bygrace Avatar answered Jan 02 '26 07:01

bygrace


Is there a lessc.bat in your path?

If so, you need to CALL lessc...


Is there an "odd" filename? being processed?

Perhaps ...do ECHO %%i& lessc -x %%i > %%~pi%%~ni.css

may reveal more...

like image 28
Magoo Avatar answered Jan 02 '26 08:01

Magoo