Looks like Java appends to %path% its own paths. Nothing else.
Videos
If you're using Java 8, you can use StringJoiner.
/**
* JEcho writes any command line argument to the standard output; each argument
* is separated by a single whitespace and end with a newline (you can
* specify '-n' to suppress the newline).
*
* This program doesn't interpret common backslash-escaped characters (for
* exampe '\n' or '\c').
*/
public class JEcho {
public static void main(String[] args) {
boolean printNewline = true;
int posArgs = 0;
if (args.length > 0 && args[0].equals("-n")) {
printNewline = false;
posArgs = 1;
}
StringJoiner outputBuilder = new StringJoiner(" ");
for (; posArgs < args.length; posArgs++) {
outputBuilder.add(args[posArgs]);
}
String output = outputBuilder.toString();
if (printNewline)
System.out.println(output);
else
System.out.print(output);
}
}
as a matter of an excersice i would advise you to keep your parameters as List<String>...
public static void main(String[] args) {
boolean printNewline = true;
List<String> parameters = new ArrayList<>(Arrays.asList(args);
if (args.length > 0 && isNewLine(args[0]) ) {
printNewline = false;
parameters.remove(0); //remove the first one
}
String output = parameters.stream()
.collect(Collectors.joining(" ", "", printNewLine ? System.lineSeparator() : "")
System.out.print(output);
}
NOTE: the method isNewLine() is not shown here - but you should consider using such a method to prevent a missing argument... think of -n, -N, /n, /N, all these parameters can be handle in the isNewLine-method...
| needs to be interpreted by a shell.
String[] cmd = {"bash", "-c", "echo 'obase=94; 100' | bc"};
Since Java 9, one can use the startPipeline method of ProcessBuilder to "creat[e] a pipeline of processes linked by their standard output and standard input streams". (c.f. https://docs.oracle.com/javase//9/docs/api/java/lang/ProcessBuilder.html#startPipeline-java.util.List-)
ProcessBuilder.startPipeline(Arrays.asList(
new ProcessBuilder("echo" , "'obase=94; 100'"),
new ProcessBuilder("bc").redirectOutput(ProcessBuilder.Redirect.appendTo(new File("out.txt")))
));
echo is not a standalone command under Windows, but embedded in cmd.exe.
I believe you need to invoke a command like "cmd.exe /C echo ...".
The > is intrepreted by the shell, when echo is run in the cmmand line, and it's the shell who create the file.
When you use it from Java, there is no shell, and what the command sees as argument is :
"foo > c:\tmp.txt"
( Which you can confirm, from the execution output )