Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WS-Man Send operation implemenation #53

Open
semancik opened this issue Mar 15, 2017 · 8 comments
Open

WS-Man Send operation implemenation #53

semancik opened this issue Mar 15, 2017 · 8 comments

Comments

@semancik
Copy link
Contributor

semancik commented Mar 15, 2017

I have implemenation of the Send WS-Man operation. The code is here:
https://github.com/Evolveum/winrm4j/tree/shell
This operation can be used to send input to the running process. With a proper PowerShell magic it can be used to initialize PowerShell once and then send several commands to an initialized instance. I have also added support for semi-async execution of commands, so winrm4j can continuously receive command output and send input as the command executes.
This is usually needed for Exchange scripts unless you want to suffer terrible penalty of exchange snap-in intialization. The sample code is here:
https://github.com/Evolveum/playground/tree/master/powerhell
However, I'm not going to create a pull request now. The code is a follow-up to my CredSSP changes which are now stuck:
#49
So I'm writing this as a note to anyone who would need the implementation of Send operation. Please go ahead and use the code from my fork.

@neykov
Copy link
Contributor

neykov commented Mar 15, 2017

That's a very interesting idea @semancik. Definitely will look into adopting the code. It also ties nicely with a cleanup of the API I have in the works.

neykov added a commit that referenced this issue Jul 8, 2017
neykov added a commit that referenced this issue Jul 8, 2017
@neykov
Copy link
Contributor

neykov commented Jul 8, 2017

Hey @semancik. It's been some time, but I finally got around to integrating your suggestion. The result is in PR #66.

I've successfully tested it with a Windows 7 machine. There's a problem when running against Windows Server 2012 though. It's not taking any input. I've been able to replicate the problem with the windows' winrs tool, which block in the same way. Not sure why it's misbihaving like this, but looks like a server-side issue.

The functionality is really useful, but if I can't get it to work on recent windows versions, then don't think it's worth including it in the winrm4j library.

Any ideas what could be causing the problem?

@semancik
Copy link
Contributor Author

I've got my version working very successfully on Windows Server 2012R2. Tested on several servers, different configurations. Seems to work well, even with CredSSP and long running powershell processes. I haven't tested your version yet. I'm afraid that I'm no windows expert or Microsoft fan. I have implemented this piece of ... ehm ... technology purely out of desperation. Therefore I have absolutely no idea what might be wrong in your case. I'm sorry.

@neykov
Copy link
Contributor

neykov commented Jul 10, 2017

That's useful to know, thanks.

@semancik
Copy link
Contributor Author

I can confirm that both CredSSP and Send operation work on both Win2008 and Win2012. However for CredSSP to work on Win2008 an improved CredSSP implementation in HTTP client is needed:
https://github.com/Evolveum/httpclient/tree/credssp

@neykov
Copy link
Contributor

neykov commented Jul 26, 2017

@semancik care to share what tool you use to test the async input with? I've been using variations of type con to echo the input to output, but would be keen on trying other approaches on win2012.

@neykov
Copy link
Contributor

neykov commented Jul 26, 2017

@semancik I'm testing your branch against my vagrant Windows 2012R2 box. Here's the test I'm using. Is that how the API is supposed to be used? What I'm seeing is that execution blocks on the send command. Can you try it against your windows box?

    @Test(groups="Live")
    public void testCustomStreams() throws Exception {
        StringBuilder inBuff = new StringBuilder();
        for (int i = 0; i < 1000; i++) {
            inBuff.append("line " + i + "\r\n");
        }

        String result;
        int exitCode;
        
        WinRmClient.Builder builder = WinRmClient.builder("http://" + VM_HOST + ":5985/wsman", AuthSchemes.NTLM);
        builder.credentials(VM_USER, VM_PASSWORD);
        builder.disableCertificateChecks(true);
        WinRmClient client = builder.build();

        try {
            Command command = client.commandAsync("type con");
            command.send(inBuff.toString());
            exitCode = command.receive();
            result = command.getLastOut();
            command.release();
        } finally {
            client.disconnect();
        }

        System.out.println("Exit code = " + exitCode);
        System.out.println(result);
    }
    

If that works for you can you also try the testCustomStreams test in #66?

@semancik
Copy link
Contributor Author

Once again I'm quite tight with available time. I'm sure that the code in my fork works. However, haven't had time to try any code from master yet. I'll have to find the time to put all this together later. I'm really sorry for this mess, but I cannot find the time now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants