头图

The contents of the file are as follows:

REM Jerry
::这是注释
@ECHO off
SETLOCAL
CALL :find_dp0

IF EXIST "%dp0%\node.exe" (
  SET "_prog=%dp0%\node.exe"
) ELSE (
  SET "_prog=node"
  SET PATHEXT=%PATHEXT:;.JS;=;%
)

"%_prog%"  "%dp0%\node_modules\@angular\cli\bin\ng" %*
ENDLOCAL
EXIT /b %errorlevel%
:find_dp0
SET dp0=%~dp0
EXIT /b

  • SETLOCAL:

Start the localization operation of the environment changes in the batch file. The environmental changes made after SETLOCAL are executed are limited to batch files. To restore the original settings, you must execute ENDLOCAL.

Start the localization of environment variables in the batch file. Localization continues until a matching endlocal command is encountered or the end of the batch file is reached.

For more details, see the windows document .

  • CALL

Invoke one batch program from another without stopping the parent batch program. The call command accepts tags as the target of the call

  • CALL :find_dp0

The magic variable %n contains the parameters used to call the file: %0 is the path of the bat file itself, %1 is the first parameter after it, %2 is the second, and so on.

Since the parameter is usually a file path, there is some additional syntax to extract part of the path. ~d is the drive, ~p is the path (without the drive), and ~n is the file name. They can be combined, so ~dp is drive + path.

So %~dp0 is very useful in bat: it is the folder where the bat file is executed.

You can also get other types of meta-information about the file: ~t is the timestamp and ~z is the size.

dp0 means the drive and path where the batch file is located.

The fifth line calls: find_dp0, which is implemented on the 18th line.

  • set: Set environment variables.

SET dp0=%~dp0

It means that the absolute path of the current batch file is set to the environment variable dp0 that is temporarily declared when the batch file is executed.

  • IF EXIST "%dp0%\node.exe"

Check whether the node.exe file exists in the same level directory of the current batch file.


注销
1k 声望1.6k 粉丝

invalid