Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Batch file - pipe to FIND

Trying to test a string to see if it contains a substring in a Windows batch file.

This is what I have so far:

echo %1 | find "message"
if %errorlevel% == 0 echo contains string

The command line output for this is (the contents of %1 was "messages\Message.js"):

messages\Message.js
contains string

The issue I am having is that the only way I can get this to work is with the exact line: echo %1 | find "js".

How can I do this without echoing the file path each time? When I remove the echo, the operating system attempts to open the file. I would love to save the file path to a variable, but nothing I tried worked, I always ended up with an empty variable.

like image 970
Chris Dutrow Avatar asked Jul 30 '12 15:07

Chris Dutrow


1 Answers

    echo %1 | find "message" > NUL
    if %errorlevel% == 0 echo contains string
like image 151
Pihhan Avatar answered Sep 19 '22 05:09

Pihhan