Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch program find string in variable

I tried to find the solutions in many places but couldn't find specific answer.

I am creating a batch script. The following is my code so far

    @echo off
    SETLOCAL EnableDelayedExpansion
    cls
    for /f "delims=" %%a in ('rasdial EVDO cdma cdma') do set "ras=!ras! %%a"

    findstr /C:"%ras%" "already"

    if %errorlevel% == 0 
    (
        echo "it says he found the word already"
    )
    else
    (
        echo "it says he couldn't find the word already"
    )

OUTPUT :

    FINDSTR: Cannot open already
    The syntax of the command is incorrect.

I'm trying to find the word 'already' in variable 'ras',

The problem seems to be in findstr /C:"%ras%" "already"

I tried using findstr "%ras%" "already" but that doesn't work too.

like image 371
Sid1024 Avatar asked Nov 15 '14 03:11

Sid1024


1 Answers

Seems I already found the solution..

    echo %ras% | findstr "already" > nul

and @Karata I can't use

    rasdial EVDO cdma cdma | findstr already > NUL

because I am writing script for multiple cases and I want to store output in a variable..Thanks anyways.

like image 147
Sid1024 Avatar answered Oct 02 '22 20:10

Sid1024