You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When executing the command, the encoding has been hard-coded. Use 436 and when receiving the returned result, the string uses the system encoding (my default system encoding is UTF-8). If the result of using the command to execute the script contains non-English, it will return garbled characters.
I hope the author can optimize this point and can specify the encoding instead.
WinRmClient.java
`
public ShellCommand createShell() {
// ...
// The encoding value here is best changed to be settable
optCodepage.setName("WINRS_CODEPAGE");
optCodepage.setValue("437");
optSetCreate.getOption().add(optCodepage);
ResourceCreated resourceCreated = winrm.create(shell, RESOURCE_URI, MAX_ENVELOPER_SIZE, operationTimeout, locale, optSetCreate);
String shellId = getShellId(resourceCreated);
return new ShellCommand(winrm, shellId, operationTimeout, retryReceiveAfterOperationTimeout, locale);
}
`
ShellCommand.java
`
private void getStreams(ReceiveResponse receiveResponse, Writer out, Writer err) {
List<StreamType> streams = receiveResponse.getStream();
for (StreamType s : streams) {
byte[] value = s.getValue();
if (value == null) continue;
if (out != null && "stdout".equals(s.getName())) {
try {
//TODO use passed locale?
if (value.length > 0) {
// Here it is best to use GBK encoding by default: new String(value, "GBK"), or you can set to use the specified encoding
out.write(new String(value));
out.flush();
}
if (Boolean.TRUE.equals(s.isEnd())) {
out.close();
}
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
if (err != null && "stderr".equals(s.getName())) {
try {
//TODO use passed locale?
if (value.length > 0) {
// Same here as above
err.write(new String(value));
err.flush();
}
if (Boolean.TRUE.equals(s.isEnd())) {
err.close();
}
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
}
}
`
The text was updated successfully, but these errors were encountered:
Hi @lnkForKing this sounds like a good improvement.
We are planning to make a new release later this year with Java 11 compatibility. I'll this to the backlog for that moment.
Fell free to open a PR with your code
When executing the command, the encoding has been hard-coded. Use 436 and when receiving the returned result, the string uses the system encoding (my default system encoding is UTF-8). If the result of using the command to execute the script contains non-English, it will return garbled characters.
I hope the author can optimize this point and can specify the encoding instead.
WinRmClient.java
`
`
ShellCommand.java
`
`
The text was updated successfully, but these errors were encountered: