为什么找不到FindStr返回 [英] Why is FindStr returning not-found

查看:555
本文介绍了为什么找不到FindStr返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

%vData%等于包含;%main%\Programs\Go\BinHKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\Path变量.
%main%是同一环境中的变量,其保留值C:\Main.

%vData% equals the HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\Path variable which includes ;%main%\Programs\Go\Bin.
%main% is a variable in the same Environment which holds the value C:\Main.

我想在添加之前检查此值是否存在,所以我有代码:

I want to check if this value exists before adding, so I have the code:

echo %vData% | FindStr /L /I /C:"%%main%%\\Programs\\Go\\Bin"

我尝试了%%main%%%main%%^main%%^^main%,但是它始终告诉我该字符串不存在.

I have tried %%main%% and %main% and %^main% and %^^main% but it consistently tells me the string does not exist.

如何获取它以证明它确实存在?

How do I get it to show me it does exist?

推荐答案

鉴于该变量确实包含文字字符串;%main%\Programs\Go\Bin(您可以通过简单地执行echo/%vData%来证明它),我相信您正在寻找它:

Given that the variable really contains the literal string ;%main%\Programs\Go\Bin (you can prove it by simply doing echo/%vData%), I believe that you are looking for this:

echo/%%vData%%| findstr /I /C:"%%main%%\\Programs\\Go\\Bin"

,甚至更好,因为vData中的特殊字符受到保护:

or, even better, since special characters in vData become protected:

cmd /V /C echo(!vData!| findstr /I /C:"%%main%%\\Programs\\Go\\Bin"


您的代码有问题:


The problem with your code:

echo %vData% | FindStr /L /I /C:"%%main%%\\Programs\\Go\\Bin"

是在新的cmd实例中执行管道|的任一侧的事实 在新的|的左侧>实例,因为它是内部命令[由于在这个问题] ,因此变量vData扩展了两次:

is the fact that either side of the pipe | is executed in a new cmd instance the left side of the pipe | is executed in a new cmd instance since it is an internal command [updated due to the finding handled in this question], so variable vData is expanded twice:

  1. 当执行整个命令行时,左侧变为:

  1. when the whole command line is executed, the left side becomes:

echo ...;%main%\Programs\Go\Bin

  • 在执行管道的左侧时,它变为:

  • when the left side of the pipe is executed, it becomes:

    echo ...;C:\Main\Programs\Go\Bin
    

  • 这篇关于为什么找不到FindStr返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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