{"id":154,"date":"2021-09-03T01:59:35","date_gmt":"2021-09-03T01:59:35","guid":{"rendered":"https:\/\/lgildv5i97.onrocket.site\/answers\/programming-search-string-assign-variables-in-bat-27963-html"},"modified":"2021-09-03T03:01:22","modified_gmt":"2021-09-03T03:01:22","slug":"programming-search-string-assign-variables-in-bat-27963-html","status":"publish","type":"question","link":"https:\/\/computing.net\/answers\/programming\/search-string-assign-variables-in-bat\/27963.html","title":{"rendered":"Solved search string &#038; assign variables in .bat"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p>Hi,<\/p>\n<p>I have an output file which may contain 3 different messages (i.e. &#8220;successfully loaded\/unloaded&#8221;, &#8220;Errors&#8221;, &amp; &#8220;Failed&#8221;). I want my .bat script to be able to search these messages through the output file and assign variable for each of the messages. Here are my requirements:<\/p>\n<p>If the file contains only &#8220;successfully loaded\/unload&#8221;, set %status%==&#8221;Success&#8221;<br \/>\nIf the file contains both &#8220;successfully loaded\/unload&#8221; &amp;&amp; &#8220;Errors&#8221;, set %status%==&#8221;Error&#8221;.<br \/>\nIf the file contains &#8220;Failed&#8221;, set %status%==&#8221;Fails&#8221;<\/p>\n<p>echo on &amp; setlocal EnableDelayedExpansion<br \/>\nset status=fails<br \/>\nset file=C:testfile.txt<\/p>\n<p>for \/f &#8220;token=*&#8221; %%a IN %file% DO<br \/>\n(<br \/>\nfindstr \/c \/i &#8220;successfully loaded\/unloaded&#8221; %%a &amp;&amp; findstr \/c \/i &#8220;Error&#8221; %%a &amp;&amp; findstr \/c \/i &#8220;Failed&#8221; %%a<br \/>\n(IF %%a==&#8221;successfully loaded\/unloaded&#8221; &amp;&amp; %%a!=&#8221;Error&#8221; (set %status%==Success echo %%a)<br \/>\nELSE IF %%a==&#8221;successfully loaded\/unloaded&#8221; &amp;&amp; %%a==&#8221;Error&#8221; (set %status%==Error echo %status%)<br \/>\nELSE set %status%==&#8221;Fails&#8221; echo %status%<br \/>\n)<br \/>\n)<\/p>\n<p>when I run the script, it&#8217;s never entered into the for loop, Could someone please help w\/ my logic &amp; syntax?<\/p>\n<p>Thanks.<br \/>\nDaigia<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","template":"","meta":{"inline_featured_image":false,"iawp_total_views":31},"question-category":[61],"question_tags":[],"class_list":["post-154","question","type-question","status-publish","hentry","question-category-netware"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question\/154","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question"}],"about":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/types\/question"}],"author":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/comments?post=154"}],"wp:attachment":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/media?parent=154"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question-category?post=154"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question_tags?post=154"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}