M
M
MasterCopipaster2021-04-26 17:31:26
cmd/bat
MasterCopipaster, 2021-04-26 17:31:26

How to ignore command response code in bat file?

Good time of the day, tell me, I ran into the following problem.
I have a bat script that rolls up updates on the site

@echo off
set /p is_migrate=Use migration?(Y/N):
@echo on
cd C:\inetpub\wwwroot
git  -c http.sslVerify=false fetch origin master
git merge origin/master
npm install
npm run build
composer update
composer dump-autoload --optimize
IF "%is_migrate%"=="Y" (
"C:\Program Files\PHP\v7.4\php.exe" -f C:\inetpub\wwwroot\bin\console doctrine:migrations:diff & 
"C:\Program Files\PHP\v7.4\php.exe" -f C:\inetpub\wwwroot\bin\console doctrine:migrations:migrate --no-interaction
)

"C:\Program Files\PHP\v7.4\php.exe" -f C:\inetpub\wwwroot\bin\console cache:clear
"C:\Program Files\PHP\v7.4\php.exe" -f C:\inetpub\wwwroot\bin\console cache:warmup
pause


But after working out the npm install command, it crashes, although the command works fine, after a little digging, I changed it to
@echo off
set /p is_migrate=Use migration?(Y/N):
@echo on
cd C:\inetpub\wwwroot
git  -c http.sslVerify=false fetch origin master
git merge origin/master
npm install & npm run build & composer update & composer dump-autoload --optimize

IF "%is_migrate%"=="Y" (
"C:\Program Files\PHP\v7.4\php.exe" -f C:\inetpub\wwwroot\bin\console doctrine:migrations:diff & 
"C:\Program Files\PHP\v7.4\php.exe" -f C:\inetpub\wwwroot\bin\console doctrine:migrations:migrate --no-interaction
)

"C:\Program Files\PHP\v7.4\php.exe" -f C:\inetpub\wwwroot\bin\console cache:clear
"C:\Program Files\PHP\v7.4\php.exe" -f C:\inetpub\wwwroot\bin\console cache:warmup
pause


After that, he began to work up to the command

composer dump-autoload --optimizeand stop, which confirmed that most likely the command, if successful, returns the wrong code that cmd.exe expects and considers that the program ended with an error, although this is not so.

I tried to do so

npm install & npm run build & composer update & composer dump-autoload --optimize & set ERRORLEVEL=0
but it did not help, the code still stops and does not work further.

Actually, how to make him ignore the response codes and continue to work no matter what?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Tsvetkov, 2021-04-26
@tsklab

does not return the code that cmd.exe expects and considers that the program ended with an error, although it did not.
The command line interpreter doesn't care how the program ends. The return code in the %ERRORLEVEL% variable. It is not checked for you, so it just composerfreezes and does not return control cmd.exe.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question