我想编写一个 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 计算机。
最佳答案
根据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。
关于python - Windows PowerShell - 与远程 PC 的 Python 脚本交互,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11704659/