Skip to content

Instantly share code, notes, and snippets.

@GaetanoPiazzolla
Last active September 18, 2021 16:32
Show Gist options
  • Select an option

  • Save GaetanoPiazzolla/04eb58ebe7e5abbc866cefb326dce500 to your computer and use it in GitHub Desktop.

Select an option

Save GaetanoPiazzolla/04eb58ebe7e5abbc866cefb326dce500 to your computer and use it in GitHub Desktop.
import java.util.*;
import org.apache.commons.lang3.SystemUtils;
public List<String> searchSo() {
List<String> found = new ArrayList<>();
// apache lang is awesome.
if (SystemUtils.IS_OS_WINDOWS) {
ProcessBuilder builder = new ProcessBuilder(
"cmd.exe", "/c", "findstr " + SEARCH_TOKEN + " c:\\temp\\big.txt");
builder.redirectErrorStream(true);
Process p = builder.start();
BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while (true) {
line = r.readLine();
if (line == null) {
break;
}
found.add(line);
}
} else if (SystemUtils.IS_OS_LINUX) {
// well. do the same thing but with grep LOL
} else {
logger.error("So not supported.");
}
return found;
}
@GaetanoPiazzolla

Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment