def test_winrs_fail_poll_process(self, wsman_conn): with WinRS(wsman_conn) as shell: process = Process(shell, "cmd.exe", ["/c", "echo", "hi"]) # if I poll before beginning it should fail with pytest.raises(WSManFaultError) as err: process.poll_invoke() assert err.value.code == 87 assert err.value.message == \ "Received a WSManFault message. (Code: 87, Machine: {0}, " \ "Reason: The parameter is incorrect., Provider: Shell cmd " \ "plugin, Provider Path: %systemroot%\\system32\\winrscmd.dll" \ ", Provider Fault: The parameter is incorrect.)"\ .format(err.value.machine) assert err.value.provider == "Shell cmd plugin" assert err.value.provider_fault == "The parameter is incorrect." assert err.value.provider_path == \ "%systemroot%\\system32\\winrscmd.dll" assert err.value.reason == "The parameter is incorrect."
def arg_check(): if len(sys.argv) < 2: print('Warning: Need to provide ip for windows instance.') sys.exit(1) if __name__ == '__main__': arg_check() server = sys.argv[1] ps = sys.argv[2] # creates a http connection with no encryption and basic auth wsman = WSMan(server, ssl=False, auth="basic", encryption="never", username="******", password="******") with WinRS(wsman) as shell: # execute a process with arguments in the background process = Process(shell, ps) process.begin_invoke() # start the invocation and return immediately process.poll_invoke() # update the output stream process.end_invoke() # finally wait until the process is finished process.signal(SignalCode.CTRL_C) print('stdout', process.stdout) print('stderr', process.stderr) print('rc', process.rc)