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

标签 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 计算机。

最佳答案

根据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/

相关文章:

windows - 如何在 CMake (Windows) 中检索用户环境变量

windows - 如何在 Windows 中使用 Go 将进程设置为 CPU?

Powershell不扩展Foreach-Object内的变量字符串

regex - Powershell - 匹配运算符不尊重正则表达式,通过设计或错误

python - pandas 应用参数没有 lambda 的函数

python - cookiecutter-django 上的数据库设置问题

python - 使用 paramiko 检查 SSH 是否可以完成

Python 在使用 open 时无法正确连接字符串

java - 使用camel文件组件从unix服务器监视Windows网络上的文件夹

powershell - 设置 TFS 构建版本号 PowerShell