Как к завершить пакетный файл окон из 'call'ed стандартная программа?

У меня была эта проблема в Windows с использованием IIS. Мой php.ini содержал следующие разделы:

[PHP_PDO_MYSQL]
extension=php_pdo_mysql.dll
[PHP_PDO]
extension=php_pdo.dll

Я просто взял разделы [PHP_PDO_MYSQL] и [PHP_PDO] и поменялся местами, так что [PHP_PDO] вышел первым. Я думаю, что порядок декларации важен!

7
задан Scott Langham 1 June 2009 в 08:48
поделиться

2 ответа

You can call your subroutines like so:

call :b||exit /b 1

which is equivalent to

call :b
if errorlevel 1 exit /b 1

It's slightly shorter and saves you one line, but it's still not ideal, I agree.

Other than that I don't see a way.

EDIT: Ok, I got a way, but it's Pure Evil™.

Misusing the maximum stack size, and therefore recursion limit, we create another subroutine which simply exhausts the stack by recursively calling itself:

@echo off
echo Calling a
call :a
echo Called a
goto :eof
:a
echo Calling b
call :b
echo Called b
goto :eof
:b
echo Trying to exit
call :exit
goto :eof
:exit
call :exit

This, however, will result in the nasty error message

******  B A T C H   R E C U R S I O N  exceeds STACK limits ******
Recursion Count=704, Stack Usage=90 percent
******       B A T C H   PROCESSING IS   A B O R T E D      ******

Also, it will take around 2 seconds on my machine.

You can suppress the error message by altering the call statement as follows:

call :exit >nul 2>&1

which will redirect everything it wants to output into a great void.

But considering the time it takes to fill the stack I think the first variant would be easier.

I was also contemplating using a second batch file, which, when run without call would essentially stop the first one. But somehow that doesn't play well with subroutines. Unrolling the call stack seemingly still takes place.

16
ответ дан 6 December 2019 в 12:54
поделиться

You could create an exit.bat file that kills the the top bat file by title name.

Example:

A.bat

@echo off
title A.bat
echo A.bat
call B.bat
echo A.bat

B.bat

@echo off
echo B.bat
exit.bat A.bat
echo B.bat

Exit.bat

@echo off
echo exit.bat
kill %1
0
ответ дан 6 December 2019 в 12:54
поделиться