I'm trying to execute the following command using java processbuilder
ls | xargs cat > pathtonewFile
Currently my code is
String command="ls | xargs cat >t"
ProcessBuilder probuilder = new ProcessBuilder(command);
probuilder.start()
Currently this executes without an error but a new file is not created.
I've tried below based on another post here: Problem Using Java ProcessBuilder to Execute a Piped Command
ProcessBuilder probuilder = new ProcessBuilder("sh", "-c", "ls | xargs cat > pathtonewfile");
The command executes but creates a 0 byte file.