Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: How to get value in variable from FINDSTR function  (Read 6144 times)

0 Members and 1 Guest are viewing this topic.

sandeep02

  • Guest
How to get value in variable from FINDSTR function
« on: September 15, 2006, 06:13:01 PM »
Hi,

Can anyone please help me out in this, this task is most important for me, Please accept my thanks in advance and help me resolving this issue.

Sandy

Please see the code below, i am trying to search for a particular string in a specific file using FINDSTR function, after that i have to execute a conditional task, mean if conditions is true than task will be executed other wise not.

PLEASE NOTE BELOW CODE IS NOT WORKING, IT IS NOT GETTING VALUE RETURNED BY FINDSTR.
===================================================================

set StatusValue =  FINDSTR StatusValue "Import finished" c:\test2.txt

echo %StatusValue%

if not '%StatusValue%' == 'Import finished'(
      echo Test successfull
      goto END      
       )      ELSE (
      goto FileNotFound
      goto END
)

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: How to get value in variable from FINDSTR func
« Reply #1 on: September 15, 2006, 06:42:12 PM »
This must be one of those puzzles that if you stare at long enough you'll go blind. I can't for the life of me see where FINDSTR is actually executed.

First up: set StatusValue = this statement is declaring a variable named [highlight]StatusValue [/highlight]; note the trailing space. This will never equate to %StatusValue%

Second up: the FINDSTR needs a search string and a filename to search; switches are optional.  You are using too many arguments.

Third up: single quotes and double quotes while both very useful, are not interchangable.

If you are trying to see if the string "Import Finished" is found in c:\test2.txt something like this may work:

Code: [Select]
@echo off
findstr /i "Import finished" c:\test2.txt
if errorlevel 1 echo Test Unsuccessful & goto end
if errorlevel 0 echo Test Successful & goto end
:end

Hope this helps.  8-)
« Last Edit: September 15, 2006, 06:47:13 PM by Sidewinder »
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

sandeep02

  • Guest
Re: How to get value in variable from FINDSTR func
« Reply #2 on: September 15, 2006, 06:49:29 PM »
Thanks a lot it resolved my problem, You are a life saver.  :)