It seems I lacked double quotes around the cmd command. Here is how I finally did it:
cmd /v:on /q /c "FOR /F "TOKENS=2 DELIMS=:." %I IN ('chcp') DO SET _codepage_=%I && SET _codepage_=Cp!_codepage_: =! && ECHO !_codepage_!"
also true as MC ND above:
cmd /q /c "FOR /F "TOKENS=2 DELIMS=:." %a IN ('chcp') DO FOR %b IN (%a) DO ECHO Cp%b"
I use this single command in Java with ProcessBuilder to get the console code page and pass it to the stdout process and String Streams:
String encoding = getConsoleEncoding(); // use the above cmd command BufferedReader stdout = new BufferedReader( new InputStreamReader(p.getErrorStream(),encoding) );
Thus, the result of system commands, for example, date / t, will correctly display in Java.
fubar
source share