How can I store the output of a grep in a file using Java?
I'm using Runtime and Process to execute the grep, then I read the InputStream
BufferedReader stdInput = new BufferedReader(new InputStreamReader(pr.getInputStream()));
and now I'd like to store the content of the grep in a file, but I'm getting an empty file.
With
String s = null;
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
I am correctly seeing the grep's output. However, when I try to write it to a file, the file is empty.
PrintWriter writer = null;
writer = new PrintWriter("grep__output", "UTF-8");
writer.println(s);
writer.close();
Also, I tried to directly writing to file in the above while (previously creating the file), but it's the same.
Pattern?