尝试使用ssh库(机器人框架)在远程服务器上执行powershell命令。
代码:
APP = "powershell.exe -noprofile -executionpolicy bypass -Command "Get-EventLog Application -EntryType Error -newest 3; [Environment]::Exit(1)"
stdout, stderr, rc = SSHConnection.execute_command(APP, return_stdout=True, return_stderr=True, return_rc=True)
print stdout, stderr, rc
问题是,如果我在powershell命令结束时没有使用[Environment]::Exit(1)
,我就不会看到任何输出回来。也许这是由于shell再次调用powershell问题。 (我不知道)
如果我不使用[Environment]::Exit(1)
,那么我会收到错误消息:
sh: -c: line 0: syntax error near unexpected token `1\'\nsh: -c: line 0: `/bin/sh.exe -c "powershell.exe -noprofile -executionpolicy bypass -Command "Get-EventLog Application -EntryType Error -newest 3; [Environment]::Exit(1) "