3

我想编写一个 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 机器。

4

1 回答 1

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.

因此,您必须在 raw_input 函数中按下(或 Powershell 可能已插入)CTRL+Z Enter。

于 2012-07-28T21:44:45.890 回答