cmd environment variable setting method example sharing
Setting environment variables in cmd can facilitate the running of our bat script, but it should be noted that the variables only have an effect in the current cmd window (local effect). If we want to set persistent environment variables, we need to set them by two means. : One is to modify the registry directly, and the other is to set the system environment variables through My Computer->Properties->Advanced.
1, View all currently available environment variables: Enter set to view.
2. Check an environment variable: Enter "set variable name". For example, if you want to check the value of the temp variable, that is Enter set temp
. Of course, you can also use echo %temp%
Modify environment variables : Enter "set variable name = variable content". For example, to set temp to "d:\tempfile", just enter set temp="d:\tempfile". Note that this modification of the environment variable refers to overwriting the previous content with the current content, not appending. For example, after I set the path above, if I re-enter set temp="c", when I check the temp path again, the value is "c", not "d:\tempfile"; "c".
4,Set to empty: If you want to set a certain variable to empty, enter "set variable name=". For example, "set path=" then the path will be empty when you check it. Note that, as mentioned above, it only works in the current command line window. Therefore, when viewing the path, do not right-click "My Computer" - "Properties"...
5,Append content to the variable (different from 3, That is overwriting): Enter "set variable name=% variable name%; variable content". For example, to add a new path for temp, enter "set path=%path%;d:\tempfile" to add d:\tempfile to the path, and execute "set path=%path%;c:" again. Then, when you use the set path statement to view, there will be: d:\tempfile;c:, instead of only c: like in step 3.
Detailed explanation of environment variables
1. View all currently available environment variables (=system variables + user variables)
set
set PATH
set xxx=aa
set xxx=
set PATH=%PATH%;d:\xxx
2. There are three main environment variables used by JAVA under Windows: JAVA_HOME, CLASSPATH, and PATH.
1) JAVA_HOME points to the JDK installation path, such as x:\j2sdk1.4.2. You should be able to find bin, lib and other directories under this path. Setting method: JAVA_HOME=c:\ j2sdk1.4.22) The role of the PATH variableWhen the java program is running, it first looks for java.exe in the path defined by the path variable, and finds it first shall prevail. If no settings are added after installing j2sdk, it is usually the C:\WINDOWS\system32 directory.
j2sdk1.4 (and other java development tools such as jbuilder8) will copy java.exe to the C:\WINDOWS\system32 directory after installation. When executing java.exe, some files under this SDK need to be loaded. .
For example, after the installation of j2sdk1.4 is completed, java.exe under C:\WINDOWS\system32 will load some necessary files in the C:\Program File\java\ directory when running. However, after installing j2sdk, C:\j2sdk1.4.2\bin will generally be set at the front of the PATH variable.
When installing j2sdk1.4.2 first, and then installing development tools such as jbuilder8, because the java.exe of jbuilder8 may overwrite the java.exe of j2sdk1.4.2 when copied to C:\WINDOWS\system32, then the java.exe running at this time java.exe will go to the directory where jbuilder8 is located to load some necessary files.
tells the class loader where to find classes provided by third parties and user-defined classes. You can also use the JVM command line parameter -classpath to specify a class path for the application respectively. The class path specified in -classpath overrides the value specified in the CLASSPATH environment variable.
3. When there are multiple SDK versions installed in the machine, how to check which SDK is used?
java -verbose
4. How to set PATH under Windows OS
[System]->[Environment]-> [Advanced], in the PATH variable Enter C:\j2sdk1.4.2\bin at the front of the text box or execute set path=c:\j2sdk1.4.2\bin;%path%; in the command line window so that any path in the command line window The java.exe program can be executed at any time. Or set PATH=%JAVA_HOME%\bin;%PATH%
5. Be extra careful when setting the CLASSPATH environment variable, because more than 80% of the inexplicable strange problems you may encounter in the future may be caused by incorrect CLASSPATH settings.
CLASSPATH=.\;%JAVA_HOME%\lib\tools.jar
The first thing to pay attention to is the first ".\;", - period backslash points Number. This tells the JDK to first search for the CLASS file in the current directory when searching for CLASS.
【Troubleshooting】
The following situations will occur during compilation. See if you really understand the settings of environment variables and can solve them.
[T1]error: java is not an operable program? Because the environment variable path
[T2] error: cannot open a directory? It may be that the setting order of the directories in the path environment variable has been ignored.
[T3]Exception on thread “main” java.lang.DoClassDefFoundError:Test? The path to classpath is not set.
cmd View environment variables
1. View all currently available environment variables: Enter set to view.
2. To view an environment variable: enter "set variable name". For example, if you want to view the value of the path variable, enter set path
3. To modify the environment variable: enter "set variable name = variable content" That's it. For example, to set path to "d:\hacker.exe", just enter set path="d:\nmake.exe". Note that this modification of the environment variable refers to overwriting the previous content with the current content, not appending. For example, after I set the path above, if I re-enter set path="c", when I check the path again, the value is "c:", not "d:\nmake.exe";" c".
4. Set to empty: If you want to set a certain variable to empty, enter "set variable name=". For example, "set path=" then the path will be empty when you check it. Note that, as mentioned above, it only works in the current command line window. Therefore, when viewing the path, do not right-click "My Computer" - "Properties"...
5. Append content to the variable (different from 3, which is overwriting): Enter "set variable Name=%Variable name%;Variable content”. For example, to add a new path to path, enter "set path=%path%;d:\hacker.exe" to add d:\hacker.exe to path, and execute "set path=%path%; again" c:", then, when using the set path statement to view, there will be: d:\hacker.exe;c:, instead of only c: like in step 3.
%ALLUSERSPROFILE% Local Returns the location of all User Profiles.
%APPDATA% Local Returns the location where the application stores data by default.
%CD% Local Returns the current directory string.
%CMDCMDLINE% Local Returns the exact command line used to start the current Cmd.exe.
%CMDEXTVERSION% System Returns the current version number of the "Command Handler Extension".
%COMPUTERNAME% System Returns the name of the computer.
%COMSPEC% System Returns the exact path to the command line interpreter executable program.
%DATE% System Returns the current date. Use the same format as the date /t command. Generated by Cmd.exe. For more information about the date command, see Date.
%ERRORLEVEL% System Returns the error code for the most recently used command. Usually a non-zero value indicates an error.
%HOMEDRIVE% System Returns the local workstation drive letter connected to the user's home directory. Setting based on home directory value. The user home directory is specified in Local Users and Groups.
%HOMEPATH% System Returns the full path to the user's home directory. Setting based on home directory value. The user home directory is specified in Local Users and Groups.
%HOMESHARE% System Returns the network path to the user's shared home directory. Setting based on home directory value. The user home directory is specified in Local Users and Groups.
%LOGONSEVER% Local Returns the name of the domain controller authenticating the current login session.
%NUMBER_OF_PROCESSORS% System Specifies the number of processors installed on the computer.
%OS% System Returns the name of the operating system. Windows 2000 displays the operating system as Windows_NT.
%PATH% System Specifies the search path for executable files.
%PATHEXT% System Returns a list of file extensions that the operating system considers executable.
%PROCESSOR_ARCHITECTURE% System Returns the chip architecture of the processor. Values: x86, IA64.
%PROCESSOR_IDENTFIER% System Returns the processor description.
%PROCESSOR_LEVEL% System Returns the model number of the processor installed on the computer.
%PROCESSOR_REVISION% System System variable that returns the processor revision number.
%PROMPT% Local Returns the command prompt settings for the current interpreter. Generated by Cmd.exe.
%RANDOM% System Returns any decimal number between 0 and 32767. Generated by Cmd.exe.
%SYSTEMDRIVE% System Returns the drive containing the Windows XP root directory (that is, the system root directory).
%SYSTEMROOT% System Returns the location of the Windows XP root directory.
%TEMP% and %TMP% System and User Returns the default temporary directory used by applications available to the currently logged in user. Some applications require TEMP, while others require TMP.
%TIME% System Returns the current time. Use the same format as the time /t command. Generated by Cmd.exe. For more information about the time command, see Time.
%USERDOMAIN% Local Returns the name of the domain that contains the user account.
%USERNAME% Local Returns the name of the currently logged in user.
%UserProfile% Local Returns the location of the current user's profile.
%WINDIR% System Returns the location of the operating system directory.
Related recommendations:
The environment variable process.env in Node.js will be explained in detail
The steps on how to configure environment variables under Linux Share (picture)
What are environment variables? The role of environment variables
The above is the detailed content of cmd environment variable setting method example sharing. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Tomato Novel is a very popular novel reading software. We often have new novels and comics to read in Tomato Novel. Every novel and comic is very interesting. Many friends also want to write novels. Earn pocket money and edit the content of the novel you want to write into text. So how do we write the novel in it? My friends don’t know, so let’s go to this site together. Let’s take some time to look at an introduction to how to write a novel. Share the Tomato novel tutorial on how to write a novel. 1. First open the Tomato free novel app on your mobile phone and click on Personal Center - Writer Center. 2. Jump to the Tomato Writer Assistant page - click on Create a new book at the end of the novel.

Unfortunately, people often delete certain contacts accidentally for some reasons. WeChat is a widely used social software. To help users solve this problem, this article will introduce how to retrieve deleted contacts in a simple way. 1. Understand the WeChat contact deletion mechanism. This provides us with the possibility to retrieve deleted contacts. The contact deletion mechanism in WeChat removes them from the address book, but does not delete them completely. 2. Use WeChat’s built-in “Contact Book Recovery” function. WeChat provides “Contact Book Recovery” to save time and energy. Users can quickly retrieve previously deleted contacts through this function. 3. Enter the WeChat settings page and click the lower right corner, open the WeChat application "Me" and click the settings icon in the upper right corner to enter the settings page.

Publishing works on Douyin can attract more attention and likes, but sometimes it may be difficult for us to publish works in real time. In this case, we can use Douyin's scheduled release function. Douyin’s scheduled release function allows users to automatically publish works at a scheduled time, which can better plan the release plan and increase the exposure and influence of the work. 1. How to set the scheduled time for publishing works on Douyin? To set a scheduled release time, first go to Douyin's personal homepage, find the "+" button in the upper right corner, and click to enter the release page. There is a clock icon in the lower right corner of the publishing page. Click to enter the scheduled publishing interface. In the interface, you can choose the type of work you want to publish, including short videos, long videos, and live broadcasts. Next, you need to set a time for your work to be published. TikTok provides

Setting font size has become an important personalization requirement as mobile phones become an important tool in people's daily lives. In order to meet the needs of different users, this article will introduce how to improve the mobile phone use experience and adjust the font size of the mobile phone through simple operations. Why do you need to adjust the font size of your mobile phone - Adjusting the font size can make the text clearer and easier to read - Suitable for the reading needs of users of different ages - Convenient for users with poor vision to use the font size setting function of the mobile phone system - How to enter the system settings interface - In Find and enter the "Display" option in the settings interface - find the "Font Size" option and adjust it. Adjust the font size with a third-party application - download and install an application that supports font size adjustment - open the application and enter the relevant settings interface - according to the individual

Mobile games have become an integral part of people's lives with the development of technology. It has attracted the attention of many players with its cute dragon egg image and interesting hatching process, and one of the games that has attracted much attention is the mobile version of Dragon Egg. To help players better cultivate and grow their own dragons in the game, this article will introduce to you how to hatch dragon eggs in the mobile version. 1. Choose the appropriate type of dragon egg. Players need to carefully choose the type of dragon egg that they like and suit themselves, based on the different types of dragon egg attributes and abilities provided in the game. 2. Upgrade the level of the incubation machine. Players need to improve the level of the incubation machine by completing tasks and collecting props. The level of the incubation machine determines the hatching speed and hatching success rate. 3. Collect the resources required for hatching. Players need to be in the game

As one of the most popular short video platforms in the world, Douyin allows everyone to become a creator and share every moment of life. For Douyin users, tags are a very important function. It can help users better classify and retrieve content, and also allows the platform to push appropriate content to users more accurately. So, where are the Douyin tags set? This article will explain in detail how to set up and use tags on Douyin. 1. Where is the Douyin tag set? Using tags on Douyin can help users better classify and label their works, making it easier for other users to find and follow them. The method to set the label is as follows: 1. Open the Douyin APP and log in to your account. 2. Click the "+" sign at the bottom of the screen and select the "Publish" button. 3.

1. Open the Weibo client, click the three little dots on the editing page, and then click Scheduled Post. 2. After clicking on scheduled posting, there will be a time option on the right side of the publishing time. Set the time, edit the article, and click on the yellow words in the lower right corner to schedule posting. 3. The mobile version of Weibo does not currently support scheduled publishing. This function can only be used on the PC client!

Even answering calls in Do Not Disturb mode can be a very annoying experience. As the name suggests, Do Not Disturb mode turns off all incoming call notifications and alerts from emails, messages, etc. You can follow these solution sets to fix it. Fix 1 – Enable Focus Mode Enable focus mode on your phone. Step 1 – Swipe down from the top to access Control Center. Step 2 – Next, enable “Focus Mode” on your phone. Focus Mode enables Do Not Disturb mode on your phone. It won't cause any incoming call alerts to appear on your phone. Fix 2 – Change Focus Mode Settings If there are some issues in the focus mode settings, you should fix them. Step 1 – Open your iPhone settings window. Step 2 – Next, turn on the Focus mode settings
