我正在寻找使用一个Windows命令来运行远程Python脚本的最快方法。到目前为止,我已经研究过Powershell,但似乎需要使用Invoke-Command
来远程启动远程Powershell脚本,然后再在本地启动Python脚本。有没有更简单,更直接的方法来做到这一点?
答案 0 :(得分:2)
你是正确的乔恩,
Invoke-Command
是对另一台计算机运行远程作业的最佳方法。
正如Ansgar在评论中所说:
Invoke-Command -Computer $remotehost -Scriptblock {python.exe 'C:\local\script.py'}
按照远程运行此操作所需的方式,将达到100%。
答案 1 :(得分:0)
为此使用Invoke-Command
,这就是它的设计目的。
Invoke-Command -ComputerName $computerName {
# Assumes python.exe is on the remote $env:PATH
# and that you are running a python file, not module
python \path\to\file.py
}
作为一项额外的奖励,如果您希望一次在多台计算机上运行此命令,-ComputerName
还可以传递一系列计算机名称,如下所示:
Invoke-Command -ComputerName computer1, computer2, computer3, computerX {
# Assumes python.exe is on the remote $env:PATH
# and that you are running a python file, not module
python \path\to\file.py
}