Windows PowerShell - 与Python脚本远程PC交互

时间:2012-07-28 21:06:54

标签: python windows powershell

我想编写一个PowerShell脚本,它将在远程PC上执行Python脚本。该脚本提示用户键入“Y”或“N”以继续执行它。

要远程登录,请输入

enter-pssession -ComputerName <Computer Name> -Credential <DOMAIN>\<username>

然后我输入:

python ".\update_software.py"

脚本在提示之前打印出文本,但是我收到以下错误消息而不是提示:

python.exe : Traceback (most recent call last):
    + CategoryInfo          : NotSpecified: (Traceback (most recent call last)::String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

 File ".\update_software.py", line 19, in <module>
_runner.execute()
 File "C:\aimplatform2\aim\software_updater\run_update.py", line 76, in execute
 res = raw_input("> ")
 EOFError: EOF when reading a line

如果有帮助,我正在运行Windows XP并远程连接到Windows XP计算机。

1 个答案:

答案 0 :(得分:2)

根据python文档,

raw_input([prompt]) -> string

Read a string from standard input.  The trailing newline is stripped.
If the user hits EOF (Unix: Ctl-D, Windows: Ctl-Z+Return), raise EOFError.
On Unix, GNU readline is used if enabled.  The prompt string, if given,
is printed without a trailing newline before reading.

所以你必须按下(或者Powershell可能已插入)CTRL + Z输入你的raw_input函数。