Java winrm4j Chinese garbled problem __ garbled problem

Source: Internet
Author: User

Because of the coding problem, Java is called by Remote Call WinRM form, in the console return character, including Chinese, display ... , there are garbled Chinese.

By adjusting the $outputencoding way, still appear garbled. So in the way of the curve implementation, the result of executing the script is obtained by redirecting the result to the file (the specified file encoding format) and then reading the file form.

The code is as follows:

Package com.test;
Import java.io.UnsupportedEncodingException;
Import java.util.ArrayList;
Import Java.util.HashMap;
Import java.util.List;

Import Java.util.Map;
Import Io.cloudsoft.winrm4j.client.WinRmClientContext;
Import Io.cloudsoft.winrm4j.winrm.WinRmTool;

Import Io.cloudsoft.winrm4j.winrm.WinRmToolResponse; public class Remotewinrm4jtest {public static void main (string[] args) throws Unsupportedencodingexception, Interrup
        
        tedexception {Winrmclientcontext context = winrmclientcontext.newinstance ();
        Winrmtool.builder Builder = WinRmTool.Builder.builder ("192.168.1.128", "Administrator", "password");
        Builder.setauthenticationscheme (AUTHSCHEMES.NTLM);
        Builder.port (5985);
        Builder.usehttps (FALSE);
        Builder.disablecertificatechecks (FALSE);
        Builder.context (context);
        Winrmtool tool = Builder.build ();
        Tool.setoperationtimeout (0L);
        System.out.println ("========"); Winrmtoolresponse Resp = tool.executeps ("C:/users/administrator/windowsauditpolicy.ps1 |out-file windowsauditpolicy_result.txt-encoding
        UTF8 ");
         Thread.Sleep (3000);
        RESP = Tool.executecommand ("type C:\\users\\administrator\\windowsauditpolicy_result.txt");
        String out = Resp.getstdout ();
        String err = Resp.getstderr ();
        System.out.println (out);
        
        
    Context.shutdown (); }

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.