0

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"
Govi
  • 1
  • 4

1 Answers1

1

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?

mmv
  • 11
  • 3
  • `ssh` may need extra options depending on what `file2.py` tries to do. For example, a `-t` option is often needed when using `sudo` on the remote – jalanb Jan 08 '19 at 19:06
  • I made the changed to the above code..but I still don't get what I want..its not changing directory..how do I define path with gnu-screen????? – Govi Jan 10 '19 at 21:02
  • I also did.."os.system('screen -S Test -X chdir "/home/user/desktop"') but its not changing the directory. – Govi Jan 10 '19 at 21:04
  • You don't run your `file2.py` remotely, as I see from your code. You try to launch `file2.py` script locally from your Laptop A via `screen`, but `screen` doesn't run scripts or programs remotely by itself. You should implement usage of `ssh` to run scrips remotely. – mmv Jan 14 '19 at 11:39
  • @mmv I am not using internet for serial communication as I am using RFD 900 radios. Is it possible to do SSH without internet? – Govi Jan 14 '19 at 17:12
  • I has no experience with connecting computers via serial connection, sorry. – mmv Jan 19 '19 at 20:26