Try to execute
ProcessBuilder pb = new ProcessBuilder("cmd.exe", "/c" ,"echo", "some text", ">", "test");
This is for windows
Actually, "Echo" is not its internal shell command (cmd.exe) on Windows and "bash" on Linux or unix . So for Unix / Linux
ProcessBuilder pb = new ProcessBuilder("bash", "-c","echo", "some text", ">", "test");
source share