简体   繁体   中英

Python script does not run after logging into computer remotely using “Screen”

Laptop A has python file "file1.py". Computer B has python file "file2.py". I want to remotely enter into Computer B and run the python script file2.py. I am using SCREEN, and below is my code.

import os 
import time

os.system('screen -S Test -d -m /dev/ttyUSB0 57600') 

time.sleep(1)

os.system('screen -S Test -X stuff "file2.py"')   
time.sleep(1)

os.system('screen -S Test -d -r')   
time.sleep(0.25) 

print "done"

How did you try to run your 'remote' script?

You can try ssh session:

ssh user@computer_b 'python file2.py'

Of course, you should provide a full path to your file2.py script and maybe (I'm not 100% sure) a full path to a Python executable on your remote Computer B. Another option is to make your file2.py executable, by adding a Python "shebang line" as the first line of your file2.py script and setting executable bit via chmod +x file2.py :

Should I put #! (shebang) in Python scripts, and what form should it take?

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