Search code examples
windowssshcommand-lineraspberry-pi

How to run local python script on remote respberry pi from windows command prompt


I have my raspberry pi connected in the network on which I have to run the python script. This python script is stored locally. I am writting command as

type <Python Script> | plink <user>@192.168.0.10 -pw <password> 'python - OFF CSM1'

But it gives me and error as

bash: line 1: python3 - OFF CSM1: command not found

What is a way to do this from windows command prompt?


Solution

  • Consider as python script the following args.py

    import sys;  print("First argument is "+sys.argv[1]+" and second argument is "+sys.argv[2])
    

    and execute the following command in Windows (in my case in powershell)

    type .\args.py | plink <theuser>@<thehostname> -pw <thepassword> 'python - FOO BAR'
    

    you get the expected result

    First argument is FOO and second argument is BAR
    

    And this works with and without quotes, being them either single or double

    type .\args.py | plink <theuser>@<thehostname> -pw <thepassword> 'python - FOO BAR'
    type .\args.py | plink <theuser>@<thehostname> -pw <thepassword> "python - FOO BAR"
    type .\args.py | plink <theuser>@<thehostname> -pw <thepassword> python - FOO BAR
    

    All commands have been verified with powershell 5.1.19041.4170 and 7.4.2 on Windows 10 Enterprise 22H2 connecting on local network to a Raspberry PI running Python 3.9.2 inside Raspberry Pi OS bullseye.

    In conclusion, your command is perfectly fine, the issue probably lies in what your answer is not specifying, which is the "<Python Script>". I am not saying the script is wrong, maybe it only is less "windows-friendly" or "plink-friendly" than needed. I suggest to start with a simpler script as I did to verify remoting and piping stuff works, then add newlines and richer instructions to deal with your relay board.