简体   繁体   中英

Windows PowerShell - Interact with Python script Remote PC

I would like to write a PowerShell script which will execute a Python script on a remote PC. The script prompts the user to type 'Y' or 'N' to continue execution of it.

To log in remotely, I type

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

Then I type:

python ".\update_software.py"

The script prints out the text before the prompt, but instead of the prompt, I receive the following error message:

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

If it helps, I am running Windows XP and remoting into a Windows XP machine.

According to python documentation,

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.

So you must have pressed (or Powershell might have inserted that) CTRL+Z Enter in your raw_input function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM