1

I Wrote a batch file to read through the text in the file produced and if it finds text named:

"LICENSE ERROR"

Also, I need to re-run the batch file until the text string is no longer there. The license error happens whenever there is no license available to run the job. But I want it to keep checking until the license is available and it will then run the job.

Below is my code and it is not working because the errorlevel is always zero, and it seems not to be reading the text file produced.

:case1
call pclrun -v 2017.2 fortrans “H:\Fortran_Folder\test_data\NETWORK"  
findstr /m "LICENSE ERROR" NETWORK.TXT
if %ERRORLEVEL%==0 goto :case1
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
chi05
  • 13
  • 5
  • `“` is not the same as `"`. Please make sure the batch file contains only straight double quotes. – Mofi Feb 17 '19 at 16:16
  • Next the command `findstr` interprets a search string like `LICENSE ERROR` specified just in double quotes as regular expression to search for `LICENSE` __OR__ `ERROR`. What you need is a case-sensitive literal search with `%SystemRoot%\System32\findstr.exe /L /M /C:"LICENSE ERROR" NETWORK.TXT >nul`. `/L` is not really needed because a search string specified with `/C:` is interpreted by default as literally interpreted search string. But `/C:` can be used also with `/R` to specify a regular expression string containing a space character not interpreted as __OR__. – Mofi Feb 17 '19 at 16:21
  • `findstr /m "LICENSE ERROR" NETWORK.TXT` searches for the upper case string `LICENSE` or the upper case string `ERROR`, anywhere inside a file named `network.txt` within the current directory, and outputs the filename `network.txt`, if either of those two strings are matched. I don't think that is what you intended! There really isn't any need to use ErrorLevel here, I'd instead choose a conditional method, `FindStr /IMC:"LICENSE ERROR" "Network.txt">Nul&&GoTo case1` – Compo Feb 17 '19 at 16:23
  • Therefore it is best practice to always specify either `/L` or `/R` to make it 100% clear for `findstr.exe` as well as for every reader of the command if the search string should be interpreted as literal or as regular expression string. And please note for the future that a space in a search string with just `"..."` is interpreted as __OR__ while a space in a search string specified with `/C:"..."` is interpreted as literal space. – Mofi Feb 17 '19 at 16:24
  • Last I recommend to run in a command prompt window `if /?` and read the output help and use `if not errorlevel 1 goto case1` working even within a command block to go to line below the line with `:case1` on exit code of `findstr` __not greater or equal 1__, i.e. equal 0 for `findstr` exit code. See also [single line with multiple commands using Windows batch file](https://stackoverflow.com/a/25344009/3074564) for an alternate solution evaluating exit code of an application on being equal 0 or not equal 0. – Mofi Feb 17 '19 at 16:28
  • Thanks you so much for your time to answer my question, I was getting the message below: Findstr cannot open the file H:\Fortran_Folder\test_data\NETWORK.txt – chi05 Feb 18 '19 at 00:47

1 Answers1

0

Try this code using && to test findstr results:

And add full path of file NETWORK.TXT if it is not in same folder..

:case1
:: add this next line to see results :: 
timeout /t 1 
call pclrun -v 2017.2 fortrans "H:\Fortran_Folder\test_data\NETWORK"  
findstr /M /C:"LICENSE ERROR" "H:\Fortran_Folder\test_data\NETWORK\NETWORK.TXT" >nul && goto :case1

Obs.:
1 - pay attention to your quote in: “H:\ this differ from "H:\

2 - May be you need wait until call pclrun to finished to perform findstr,

try replace call to start "" /w pclrun...

Io-oI
  • 2,514
  • 3
  • 22
  • 29
  • Whilst `FindStr` may work for the purpose of this question, `/C` alone is sufficient to escape the space character. There's no need to include the `/L` option, because none of the other string characters can be taken as anything other than literal. In fact, it is likely that the search string is also only ever found in upper case, and as we aren't using any returned output, we could probably forget about both the `/I` and `/M` options too, i.e. `FindStr /C:"LICENSE ERROR"`. This means of course that we could forget about the `FindStr` command and use `Find` instead, i.e. `Find "LICENSE ERROR"` – Compo Feb 17 '19 at 18:36
  • Find "LICENSE ERROR" was able to work than Findstr Thank you so much!! – chi05 Feb 18 '19 at 01:15
  • Nice!! @Compo and //Mofi have help me to do this answer, so, thanks accepted to they too. – Io-oI Feb 18 '19 at 01:20
  • Thank you to every one that helped me with the solution. You guys are amazing and I am happy to join this community. – chi05 Feb 19 '19 at 04:41