Findstr does not work with SET /P?

▼魔方 西西 提交于 2019-12-02 17:45:41

问题


I have a batch file with a portion shown below:

    rem @echo off
    cd C:\Program Files\CA\AllFusion Gen\GEN\test8.ief\c\
    FINDSTR /C:"'V1600 OPER'"  /C:"'V1714 OPER'" /C:"'V1801 OPER'" /C:"'V1901 OPER'" "MPOAD10C"

The above batch file runs successfully with the above code. However, when I modified the script so that the user can enter two variables, as shown below (%path%=test8.ief,%file_name%=MPOAD10C), it throws the following error:

'FINDSTR' is not recognized as an internal or external command,operable program or batch file.

    rem @echo off
    SET /P path=Enter name of IEF folder:
    echo. && echo.
    SET /P file_name=Enter name of file:
    echo. && echo.
    cd C:\Program Files\CA\AllFusion Gen\GEN\%path%\c
    FINDSTR /C:"'V1600 OPER'" /C:"'V1714 OPER'" /C:"'R18 V1801 OPER'" /C:"'V1901 OPER'" "%file_name%"

I have also entered the value "C:\WINDOWS\system32" in the PATH variable in the Environment Variables.

I am very new to batch scripting. Please help. Thanks in advance.

Regards, Mohit Gupta.


回答1:


Don't use path as one of your own variables, that particular environment variable is used by Windows to locate executable files, such as findstr as you've just discovered.

Change it to something like mypath and your problem should disappear.




回答2:


To fix this, use a name other than %PATH% to capture the user's input.

%PATH% is a special variable that controls where the command interpreter searches for executables. When you modify %PATH% with your SET /P, you change where the command interpreter will look for FINDSTR. It cannot find FINDSTR.EXE in the new location in %PATH%, hence the error that "'FINDSTR' is not recognized as an internal or external command"



来源:https://stackoverflow.com/questions/21901077/findstr-does-not-work-with-set-p

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!