I am trying to run this command from java code and expecting a file to be generated with 1 liner code :
cut -d , -f 2 /online/data/test/output/2Zip/brita_ids-*.csv | sort -u | tr -d '\n' | sha512sum > /online/data/test/output/file_name.txt
This cmd is fine when I am running from cmd line but something wrong with my java code that I gatting hard time to figure out and I am not seeing the expected file being generated. Any clue whay may have happened here?
Here is my code to generate that file :
public String executeCommand(String command) {
StringBuffer output = new StringBuffer();
Process p;
try {
LOG.info( "Executing cmd : " + command );
p = Runtime.getRuntime().exec(command);
p.waitFor();
BufferedReader reader =
new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
while ((line = reader.readLine())!= null)
{
output.append(line + "\n");
}
} catch (Exception e) {
e.printStackTrace();
LOG.error( "Error in executing cmd : " + command + " \nError : " + e.getMessage() );
}
return output.toString();
}
Thanks in advance.