echo print double quotes in text file even if the command does not contain that [closed]

1 week ago 5
ARTICLE AD BOX

This is my code sample:

ProcessBuilder pb = new ProcessBuilder( "cmd.exe", "/c", "chcp 65001 > nul && " + this.cmd ); pb.redirectErrorStream(true); Process p = pb.start(); if (!this.isAsync()) { BufferedReader input = new BufferedReader(new InputStreamReader(p.getErrorStream(), "UTF-8")); StringBuffer sb = new StringBuffer(); String line = null; while ((line = input.readLine()) != null) { sb.append(line); } input = new BufferedReader(new InputStreamReader(p.getInputStream(), "UTF-8")); while ((line = input.readLine()) != null) { sb.append(line); } p.waitFor(); streamWorkerImpl.addLastResult(this.getNodeUUID(), sb.toString()); } else { p.waitFor(); }

If this.cmd is echo Hello World > C:\Users\edit\Desktop\san.txt
I get Hello World in my txt file, which is correct.

But if this.cmd is echo Hello World > C:\Users\edit\Desktop\san.txt,
that is, if it contains multiple spaces between Hello and World, I get "Hello World" in double quotes. Do you know why this is and how to get rid of it?

Read Entire Article