怎么在命令行打印path
Have you ever wondered why you can just type ipconfig
into a command prompt and it works, but when you want to use a command line program you downloaded you have to navigate to its directory first? Here’s how to fix that using the Windows System PATH.
您是否曾经想过为什么只能在命令提示符下键入ipconfig
并起作用,但是当您要使用下载的命令行程序时,必须先导航到其目录? 这是使用Windows系统PATH修复此问题的方法。
什么是Windows系统路径? (What Is the Windows System PATH?)
If you’ve downloaded a program for the Command Prompt–like ADB, the Android Debugging Bridge–you can’t just type adb
in the Command Prompt to run it, like you can with Windows’ built-in commands (e.g. ipconfig
). Instead, you have to tell Command Prompt where to find that file, by typing in the full path of the EXE:
如果您已经下载了命令提示符程序(例如ADB, Android Debugging Bridge),则不能像在Windows内置命令(例如ipconfig
)中那样在命令提示符中键入adb
来运行它。 相反,您必须通过键入EXE的完整路径来告诉命令提示符在哪里找到该文件:
C:\Android\platform-tools\adb.exe
That’s a lot of typing, though, especially for something you have to run often.
但是,这需要大量输入,尤其是对于您必须经常运行的内容。
The Windows System PATH tells your PC where it can find specific directories that contain executable files. ipconfig.exe
, for example, is found in the C:\Windows\System32
directory, which is a part of the system PATH by default. When you type ipconfig
into a Command Prompt, Windows doesn’t need to know where that EXE is–it’ll check all the folders in its PATH until it finds the right one.
Windows系统PATH告诉您的PC在哪里可以找到包含可执行文件的特定目录。 例如, ipconfig.exe
在C:\Windows\System32
目录中,该目录默认是系统PATH的一部分。 在命令提示符下键入ipconfig
,Windows不需要知道该EXE的位置–它会检查PATH中的所有文件夹,直到找到正确的文件夹为止。
If you want the same convenience with a program you downloaded (like ADB), you need to add its folder to Windows’ system PATH. That way, when you need to run adb, you can just run:
如果您希望下载的程序(如ADB)具有相同的便利性,则需要将其文件夹添加到Windows的系统PATH中。 这样,当您需要运行adb时,只需运行:
adb
No extra typing necessary.
无需额外输入。
如何将文件夹添加到您的PATH (How to Add a Folder to Your PATH)
The first several steps of the process are the same for Windows 7, 8, and 10. Start by pressing the Windows key to open up the Start Menu or Start Screen, then search for “advanced system settings.” You can alternatively browse through Control Panel to System and Security > System and click on the Advanced system settings hyperlink in the left hand pane.
该过程的前几个步骤与Windows 7、8和10相同。首先,按Windows键打开“开始”菜单或“开始”屏幕,然后搜索“高级系统设置”。 您也可以在控制面板中浏览到“系统和安全性”>“系统”,然后单击左侧窗格中的“高级系统设置”超链接。
Once the System Properties window opens, click on the “Environment Variables” button.
系统属性窗口打开后,单击“环境变量”按钮。
In the “System Variables” box, look for a variable called Path. Select that and click on the “Edit” button.
在“系统变量”框中,查找名为Path的变量。 选择它,然后单击“编辑”按钮。
This is where things are different between the versions of Windows—it’s the same for 7 and 8, but slightly different (and easier) in Windows 10.
这是Windows版本之间有所不同的地方-7和8相同,但Windows 10中略有不同(并且更容易)。
在Windows 7和8中 (In Windows 7 and 8)
In 7 and 8, the variable value for Path is nothing more than a long string of text with various locations around the system. We’ve put the ADB executables in C:\Android\platform-tools
on our machine, so that’s the location we’re going to add.
在7和8中,Path的变量值不过是一长串文本,在系统中的各个位置都有。 我们已将ADB可执行文件放在我们计算机上的C:\Android\platform-tools
,因此这是我们要添加的位置。
In order to add an entry to your path in Windows 7 and 8, you have to precede the folder with a semicolon, like so:
为了在Windows 7和8中将条目添加到您的路径中,您必须在文件夹前面加上分号,如下所示:
;C:\Android\platform-tools
Add that exact line at the end of the variable value (make sure not to delete any of the existing text in the value!) without a space. Click OK, and you’re done. Simple.
在变量值的末尾添加该行(请确保不要删除该值中的任何现有文本!),不要留空格。 单击确定,完成。 简单。
在Windows 10中 (In Windows 10)
In Windows 10, this process is both easier and less confusing. Once you’ve clicked the edit button, a new dialog box will appear with each location in the path on a separate line. This is a dramatic improvement over the way previous versions of Windows handled path locations, and makes easy work of adding a new one.
在Windows 10中,此过程既简单又混乱。 单击编辑按钮后,将出现一个新对话框,路径中的每个位置均位于单独的一行。 与以前版本的Windows处理路径位置的方式相比,这是一个巨大的改进,并且使添加新路径变得容易。
First, click the ‘new’ button, which will add a line at the end of the list. Add your location— C:\Android\platform-tools
in our example—and hit Enter. There is no need to add a semicolon like in Windows 7 and 8. Click the “OK” button and you’re finished.
首先,点击“新建”按钮,这将在列表末尾添加一行。 添加您的位置(在我们的示例中为C:\Android\platform-tools
,然后按Enter。 无需像Windows 7和8那样添加分号。单击“确定”按钮,操作完成。
The Android Debugging Bridge should now be accessible from any command prompt, no need to specify its directory.
现在,可以从任何命令提示符访问Android调试桥,而无需指定其目录。
翻译自: https://www.howtogeek.com/118594/how-to-edit-your-system-path-for-easy-command-line-access/
怎么在命令行打印path