Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top