I have a method
final ProcessBuilder processBuilder = new ProcessBuilder(this.cmd);
processBuilder.redirectErrorStream(true);
try {
final Process process = processBuilder.start();
try (final BufferedReader reader =
new BufferedReader(
new InputStreamReader(
process.getInputStream()
)
)
) {
while (reader.ready()) {
System.out.println(reader.readLine());
}
process.waitFor(this.timeOut, TimeUnit.SECONDS);
}
} catch (final Exception exc) {
throw new IllegalStateException("Terminal command execution exception", exc);
}
This method takes cmd(array of strings) from Constructor and then executes it. This is the value of cmd
new String[]{"cat","$(cat /home/Downloads/tmp/aqnYtUSVFp.txt)",">","/home/Downloads/hello.ts"}
So the whole command is looks like this cat $(cat home/Downloads/tmp/aqnYtUSVFp.txt) > /home/Downloads/hello.ts
It works fine if I run it within terminal , but ProcessBuilder shows me the following error
cat: '$(cat /home/Downloads/aqnYtUSVFp.txt)': No such file or directory
cat: '>': No such file or directory
cat: /home/Downloads/hello.ts: No such file or directory
What did I miss . Why ProccBuilder doesn't recognize this command ?