How to run this Runtime.getRuntime().exec("cat finename grep ,000 wc -l"
Hi,
I dont know how to run this ,
To get number of line in Linux , we put as
Cat file.txt | grep ,000 | wc -l
I have to put in
Runtime.getRuntime().exec(" Cat file.txt | grep ,000 | wc -l ");
but null is returning in
how to give this
Thanks,
Kamal.
# 1
I think you're using it wrong, try this...
try {
Process process = Runtime.getRuntime().exec(" Cat file.txt | grep ,000 | wc -l");
/*
*OR process = Runtime.getRuntime().exec(new String[]{"Cat","file.txt","|","grep",",000","|","wc","-1"});
*/
BufferedReader inputReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
/*
* The following block should be in its own thread.. because readLine() blocks.
*/
while (((line = inputReader.readLine()) != null)) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}