简体   繁体   中英

Using SSH in Raspberry Pi to get Input?

I need to run Python scripts from SSH on my Raspberry Pi, while still being able to get input from a user on the Raspberry Pi via a USB keyboard emulator ( card reader ). I would normally be able to use raw_input for this, but if I run the Python script through SSH, it does not create a window and it will not be active so it will receive no input.

Is there any way to ensure a Python script will be active (the top window), even while using SSH to launch it? Or, is there another way to get user input without using raw_input , and works in the background (without an active window)?

Thanks in advance :)

PS: If I have to use other languages (like C) then invoke it in Python, this is fine, I will be able to do that.

I've solved it the best I can, with help from @Gaurav Dave

I now have a script which creates a new terminal window upon launch, using Popen from sys . The script looks like this...

from sys import executable
from subprocess import Popen, CREATE_NEW_CONSOLE

Popen([executable, 'window.py'], creationflags=CREATE_NEW_CONSOLE)

and window.py is simply a test script that prints some text and waits for a certain amount of time...

import time
print("Hello M8!")
time.sleep(5)

window.py will be the script that takes the input as that is the one that has the window.

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