Skip to content

Conversation

@mypaceshun
Copy link

Hello,
First of all, thank you for creating pywinrm.

The send_command_input function is added #271.
This function is very useful for sending data to stdin of remote commands.
I have made send_command_input function available from winrm.Session.

This PR add new option stdin_input to winrm.Session.run_cmd and winrm.Session.run_ps.

  • When stdin_input is None, send_command_input is not called
  • When stdin_input is str or bytes, send_command_input is called after run_command

Example for sending data to stdin

Before

import winrm

session = winrm.Session("win-server", ("user", "pass"))
shell_id = session.protocol.open_shell()
command_id = session.protocol.run_command(shell_id, "command")
session.protocol.send_command_input(shell_id, command_id, "input data", True)
std_out, std_err, status_code = session.protocol.get_command_output(shell_id, command_id)

session.protocol.cleanup_command(shell_id, command_id)
session.protocol.close_shell(shell_id)

print(std_out)

After

import winrm

session = winrm.Session("win-server", ("user", "pass"))
response = session.run_cmd("command", stdin_input="input data")

print(response.std_out)

Add stdin_input option in winrm.Session.run_cmd and
winrm.Session.run_ps. When stdin_input is specified as str or bytes,
send_command_input is called after Protocol.run_command.
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

Successfully merging this pull request may close these issues.

1 participant