如何从 Windows 命令提示符在远程 respberry pi 上运行本地 python 脚本

问题描述 投票:0回答:1

我的树莓派已连接到网络中,我必须在该网络上运行 python 脚本。该Python脚本存储在本地。我正在将命令写为

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

但是它给了我错误

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

从 Windows 命令提示符执行此操作的方法是什么?

windows ssh command-line raspberry-pi
1个回答
0
投票

将以下内容视为 python 脚本

args.py

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

并在 Windows 中执行以下命令(在我的例子中是在 powershell 中)

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

你得到了预期的结果

First argument is FOO and second argument is BAR

无论带引号还是不带引号,都可以使用单引号或双引号

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

所有命令均已在 Windows 10 Enterprise 22H2 上使用 powershell 5.1.19041.4170 和 7.4.2 进行验证,在本地网络上连接到在 Raspberry Pi OS bullseye 内运行 Python 3.9.2 的 Raspberry PI。

总之,您的命令完全没问题,问题可能在于您的答案未指定什么,即“”。 我并不是说脚本是错误的,也许它只是比需要的“windows 友好”或“plink 友好”程度低。 我建议像我一样从一个更简单的脚本开始,以验证远程处理和管道的工作是否正常,然后添加换行符和更丰富的指令来处理您的中继板。

© www.soinside.com 2019 - 2024. All rights reserved.