masterzen / winrm

Command-line tool and library for Windows remote command execution in Go
Apache License 2.0
425 stars 129 forks source link

Direct command, doesn't use pipes #127

Open willemm opened 2 years ago

willemm commented 2 years ago

New directcommand.go with object that sends commands directly to the remote. Noprofile and consolemode_stdin off, so remote powershell doesn't think it's interactive

This can be used to run a shell on the remote side, and then repeatedly send commands to that shell and receive their output.

I use this (in https://github.com/willemm/cluster-api-provider-scvmm) to open a powershell remotely and then run a number of cmdlets on it, which is much cleaner and faster than sending each statement as a commandline-option to powershell.exe

masterzen commented 2 years ago

Your PR proposes an incompatible change with respect to WINRS_NOPROFILE and WINRS_CONSOLEMODE_STDIN. I would favor those to be injected into the request instead of being changed for every command. You could for instance modify your direct command system to make sure those options are set how they should.

Would you mind adding some documentation about the direct command system in a section of the README?

willemm commented 2 years ago

Good point. I'll look into how to set those dynamically, and write up some documentation.

willemm commented 2 years ago

I wasn't able to put it in the direct-command system because that only applies after a shell has been created, and the options in question are applied when connecting/creating the shell. So I decided to just add an options field to the parameters where these options (along with the other two, i.e. codepage and skip_cmd) can be set.

I've also documented this in the readme, along with the workings of directcommand. I hope my descriptions are clear enough :)