Windows%PATH%变量-如何分割';'再次在CMD shell中 [英] windows %PATH% variable - how to split on ';' in CMD shell again

查看:199
本文介绍了Windows%PATH%变量-如何分割';'再次在CMD shell中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚检查了 stackoverflow 似乎很有帮助,并且在Windows XP上也能正常工作.但是,由于某些晦涩的原因,使用Windows 7不能正常工作.

I just checked stackoverflow that seemed to be very helpful and worked fine on Windows XP. But using Windows 7 it does not work for some obscure reason.

PATH变量看起来像这样

C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\QuickTime\QTSystem\

它显然包含\以及我用来分割包含此FOR循环的批号的分号:

It obviously contains \ as well as semicolons I use to split in a batch that contains this FOR-loop:

   FOR /F "delims=;" %%A IN ("%PATH%") DO (
      echo %%A
   )

执行不会导致任何错误,但仅提供一个(第一个)令牌

Executing does not cause any error but it provides just one (the first) token

C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common

我不知道为什么FOR会终止并尝试使用网上提出的几种变体,但没有一项工作完成.

I had no idea why FOR terminates and played around with several variations that have been suggested on the net but none did the job.

任何帮助将不胜感激.

基督徒

推荐答案

您可以这样做.

for %%A in ("%path:;=";"%") do (
    echo %%~A
)

(来源)

使用方式的问题在于,使用for /F开关,%%A仅指定第一个令牌.您将必须执行for /f "tokens=1-9 delims=;" %%A in ("%PATH%")并通过%%I读入%%A.

The problem with the way you have it is that, using the for /F switch, %%A only specifies the first token. You would have to do for /f "tokens=1-9 delims=;" %%A in ("%PATH%") and read in %%A through %%I that way.

这篇关于Windows%PATH%变量-如何分割';'再次在CMD shell中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆