Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
330 views
in Technique[技术] by (71.8m points)

windows - 在Windows中将目录添加到PATH环境变量(Adding directory to PATH Environment Variable in Windows)

I am trying to add C:\xampp\php to my system PATH environment variable in Windows. (我试图将C:\xampp\php添加到Windows中的系统PATH环境变量中。)

I have already added it using the Environment Variables dialog box. (我已经使用“环境变量”对话框添加了它。)

But when I type into my console: (但是当我输入控制台时:)

C:>path

it doesn't show the new C:\xampp\php directory: (它不显示新的C:\xampp\php目录:)

PATH=D:Program FilesAutodeskMaya2008in;C:Ruby192in;C:WINDOWSsystem32;C:WINDOWS;
C:WINDOWSSystem32Wbem;C:PROGRA~1DISKEE~2DISKEE~1;c:Program FilesMicrosoft SQL
Server90Toolsinn;C:Program FilesQuickTimeQTSystem;D:Program FilesTortoiseSVNin
;D:Program FilesBazaar;C:Program FilesAndroidandroid-sdkools;D:Program Files
Microsoft Visual StudioCommonToolsWinNT;D:Program FilesMicrosoft Visual StudioCommon
MSDev98Bin;D:Program FilesMicrosoft Visual StudioCommonTools;D:Program Files
Microsoft Visual StudioVC98in

I have two questions: (我有两个问题:)

  1. Why did this happen? (为什么会这样呢?) Is there something I did wrong? (我做错了什么吗?)
  2. Also, how do I add directories to my PATH variable using the console (and programmatically, with a batch file)? (另外,如何使用控制台(以编程方式,使用批处理文件)将目录添加到PATH变量中?)
  ask by Mp de la Vega translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Option 1 (选项1)

After you change PATH with the GUI, close and re-open the console window. (使用GUI更改PATH之后,关闭并重新打开控制台窗口。)

This works because only programs started after the change will see the new PATH . (之所以可行,是因为只有在更改后启动的程序才能看到新的PATH 。)

Option 2 (选项2)

Execute this command in the command window you have open: (在打开的命令窗口中执行以下命令:)

set PATH=%PATH%;C:yourpathhere

This command appends C:\your\path\here\ to the current PATH . (此命令将C:\your\path\here\附加到当前PATH 。)

Breaking it down: (分解:)

  • set – A command that changes cmd's environment variables only for the current cmd session ; (set更改当前cmd会话的 cmd环境变量的命令 ;) other programs and the system are unaffected. (其他程序和系统不受影响。)
  • PATH= – Signifies that PATH is the environment variable to be temporarily changed. (PATH= –表示PATH是要临时更改的环境变量。)
  • %PATH%;C:\your\path\here\ – The %PATH% part expands to the current value of PATH , and ;C:\your\path\here\ is then concatenated to it. (%PATH%;C:\your\path\here\%PATH%部分扩展为PATH的当前值,然后将;C:\your\path\here\与其连接。) This becomes the new PATH . (这成为新的PATH 。)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...