I'd like to use findstr to see if a string exists or not within one or multiple directories. I found that for example findstr /c:\"word\" /d:C:\test;C:\test1 *.txt works fine within command prompt (given folders are made and whatnot), but I was wondering how I could implement this within a java method in order to run this command within an app, then do whatever depending on the output returned. From my google search, I tried the following:
What I was given back in the console was "C::" I'm not exactly sure what this means, but like I said the command does work in command prompt so I was expecting the same return value. I have also tried using process builder in order to do this, but as expected it gave me the same output.
Perhaps I did something wrong for the param of the exec method? Really unsure. Any help would be appreciated.
posted 8 years ago
\ is a special character in Java strings which is used to escape other characaters - one of the characters it can be used to escape is a 't', \t in a Java string actually represenst a tab
" is also a special character (it marks the beginning and end of of a string literal - if you want an actual " in your string you need to escape it with a \.
So the actual command you are running is
findstr /c"word" /d:C:<tab>est;C:<tab>est1 *.txt
which is probably why you are getting strange results.