I need to run a command from my java application and process its output. The code is as follows:
public static void readAllOutput(){
try {
final String cmd = new String("find ~ -iname \"screen*\"");
System.out.println(cmd);
Process ps = Runtime.getRuntime().exec(cmd);
BufferedReader reader = new BufferedReader(new InputStreamReader(ps.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
}
When I execute this command from the OS, I have a lot of output, but in my Java application the output is emty.
source
share