admin管理员组

文章数量:1432196

I have this batch file but can't get it to return control after chaining commands:

set hostingDir=%cd%
cd "%hostingDir%\MVC\wwwroot
call webpack --config webpack.config.js --stats=summary

cd "%hostingDir%\MVC\wwwroot\styles"

REM Compile LESS files
call "E:\Node\lessc" --glob --source-map --clean-css "style.less" "style.min.css"^
&& "E:\Node\lessc" --glob --source-map --clean-css "style-below.less" "style-below.min.css"
 
REM Return to base directory -- don't get to here
cd %hostingDir%

PAUSE

However, if I remove the chaining and call lessc on only either of the 2 less files, the entire script executes. So I know there is nothing wrong with the less files themselves. I deleted the compiled files and ran again to make sure they compile and they do. Even with both commands chained together.

I have this batch file but can't get it to return control after chaining commands:

set hostingDir=%cd%
cd "%hostingDir%\MVC\wwwroot
call webpack --config webpack.config.js --stats=summary

cd "%hostingDir%\MVC\wwwroot\styles"

REM Compile LESS files
call "E:\Node\lessc" --glob --source-map --clean-css "style.less" "style.min.css"^
&& "E:\Node\lessc" --glob --source-map --clean-css "style-below.less" "style-below.min.css"
 
REM Return to base directory -- don't get to here
cd %hostingDir%

PAUSE

However, if I remove the chaining and call lessc on only either of the 2 less files, the entire script executes. So I know there is nothing wrong with the less files themselves. I deleted the compiled files and ran again to make sure they compile and they do. Even with both commands chained together.

Share Improve this question asked Nov 19, 2024 at 11:55 roryrory 1,4384 gold badges26 silver badges52 bronze badges 4
  • 1 I'd suggest, at a guess given the extensive documentation on lessc, that you try %% CALL "E:\Node\… – Magoo Commented Nov 19, 2024 at 12:10
  • 4 If you try to use && in a new line, then you must prefix it with a space. And the second line should also use CALL – jeb Commented Nov 19, 2024 at 12:40
  • @jeb thank you! please make this an answer so I can mark it as correct! – rory Commented Nov 19, 2024 at 12:44
  • The first line you've posted should be deleted, the second should read as CD "MVC\wwwroot, the next line should read as Call webpack.cmd --config webpack.config.js --stats=summary, then the next line as just CD styles. You should also use E:\Node\lessc.cmd too. e.g. Call "E:\Node\lessc.cmd" --glob --source-map --clean-css "style.less" "style.min.css" && Call "E:\Node\lessc.cmd" --glob --source-map --clean-css "style-below.less" "style-below.min.css". Then finally CD ..\..\... – Compo Commented Nov 19, 2024 at 12:48
Add a comment  | 

1 Answer 1

Reset to default 1

Two problems.

  • If you try to use && in a new line, you must prefix it with a space, otherwise the first & will be escaped and the second command will be executed unconditionally.
  • Both commands should use CALL, because if lessc is a batch file, it would otherwise not return to the caller

本文标签: cmdBatch file call lessc not returning control despite executing successfullyStack Overflow