BAT script path information of CMD command

CD Command Troubleshooting

cd is the abbreviation of chdir. For details of the command, seecd /?

It can be seen that the explanation of the /d parameter is as follows:
Using the /D command line switch, in addition to changing the current directory of the drive, you can also change the current drive.

Usually when we open the cmd window in the XP system, it will display
C:\Documents and Settings\Administrator>
If we execute the following command, we find that the directory is still in C:\Documents and Settings\Administrator
C:\Documents and Settings\Administrator> cd d:\tomcat6.0.18
C:\Documents and Settings\Administrator>
At this point, when we type d:, it will not only switch to the d drive, but also switch to the directory
C:\Documents and Settings\ of d:/tomcat6.0.18 Administrator>cd d:\tomcat6.0.18
C:\Documents and Settings\Administrator>d:
D:\tomcat6.0.18>
The following statement we can see the role of the /d parameter. It was found that after adding the /d parameter, it was directly switched to the tomcat6.0.18 directory of the d disk.
C:\Documents and Settings\Administrator>cd /dd:\tomcat6.0.18
D:\tomcat6.0.18>

Conclusion: Without the /d parameter, you can only switch between directories in the same drive, and with the /d parameter, you can switch between directories in different drives

The difference between %cd% and %~dp0 in DOS batch processing

In DOS, there are two environment variables that can be related to the current path, one is %cd%, and the other is %~dp0.

  • %cd% can be used in batch files or command lines; the content of %cd% can be changed, and its content is the execution path of the command or the execution path of the batch file.
  • %~dp0 can only be used in batch files, and its content is the path where the batch files are located.

This command is not clear, the following contents are all from the Internet:
%~dp0 "d" is the abbreviation of Drive, which is the drive, disk, "p" is the abbreviation of Path, which is the path, the directory
cd is to go to this directory, but I think cd /d %~dp0 is better
Option syntax:
~0 - remove any quotes ("), expand %0

  • %~f0 - expands %0 to a fully qualified pathname ("f" is file, i.e. file)
  • %~d0 - expands %0 to a drive letter only
  • %~p0 - expands %0 to a path only
  • %~n0 - just expand %0 to a filename ("n" is the name filename)
  • %~x0 - only expands %0 to a file extension
  • %~s0 - the expanded path contains only short names ("s" is Short, short)
  • %~a0 - expands %0 to the file attribute of the file ("a" is attribute, ie attribute)
  • %~t0 - expand %0 to the date/time of the file ("t" time)
  • %~z0 - expand %0 to the size of the file (Size size)
  • %~$PATH:0 - Look up the directories listed in the PATH environment variable and expand %0 to the first fully qualified name found. If the environment variable name is not defined, or the file is not found, this key combination expands to the empty string

Modifiers can be combined to get multiple results:

  • %~dp0 - just expand %0 to a drive letter and path
  • %~nx0 - expands %0 to a filename and extension only
  • %~fs0 - just expand %0 to a full pathname with a short name
  • %~dp$PATH:0 - Find the directory listed in the PATH environment variable and expand %I to the first drive letter and path found.
  • %~ftza0 - expands %0 to DIR like output line
  • %0 is the current batch file if 0 is replaced by 1 for the first file and 2 for the second
@echo off
echo %%cd%%      %cd%

echo %%0         %0
echo %%~d0       %~d0
echo %%~p0       %~p0
echo %%~dp0      %~dp0
echo %%~n0       %~n0
echo %%~x0       %~x0

echo %%~f0       %~f0
echo %%~s0       %~s0
echo %%~fs0      %~fs0
echo %%~a0       %~a0
echo %%~t0       %~t0
echo %%~z0       %~z0
echo %%~ftza0    %~ftza0
echo %%~$PATH:0  %~$PATH:0

Results of the

Setting environment variables in BAT

After the software is installed, either automatically add environment variables, or manually add the corresponding environment variables. For large system green installations, it is essential to set temporary environment variables in BAT, such as MinGW startup scripts.

Here is the script for green install to start appium:

@echo off

set CLASSPATH=.;%~dp0\Java\jdk1.8.0_66\lib
set JAVA_HOME=%~dp0\Java\jdk1.8.0_66
set JDK_HOME=%~dp0\Java\jdk1.8.0_66
set ANDROID_HOME=%~dp0\Android\android-sdk
set PATH=%~dp0\Android\android-sdk\platform-tools;%~dp0\Java\jdk1.8.0_66\bin;%~dp0\Android\android-sdk;%PATH%

adb connect 127.0.0.1:62001
"Android\android-sdk\platform-tools\adb.exe" devices

"%~dp0\node_modules\node.exe"  "%~dp0\node_modules\appium\bin\appium.js" -U 127.0.0.1:62001

The environment variables related to java and android are set here, and the software package can be copied to other machines to run the script to start appium

Customize the terminal for specific environment variables

Shortcut

For example, the squid terminal sets its bin path to the PATH environment variable, and its shortcut target is as follows:

C:\Windows\System32\cmd.exe /K "color 02 & cd /dD:\Squid\ & set PATH=D:\Squid\bin;%PATH%"

Node's terminal environment

@echo off

%ComSpec% /K "color 02 & set PATH=D:\Program Files\node-v6.11.3-win-x64;%PATH% & set NODE_PATH=D:\Program Files\node-v6.11.3-win-x64\node_modules"

Common parameters of cmd.exe are as follows:

  • /c Executes the command specified by String, then stops.
  • /k Executes the command specified by String and continues.

Enabling and disabling the Administrator user

Admin executes:
- disable net user administrator /active:no
- enablenet user administrator /active:yes

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325656428&siteId=291194637