首页 > 解决方案 > 使用powershell执行的批处理文件在远程机器上启动python

问题描述

我想使用命令行参数运行位于远程机器上的 python 脚本。

我正在使用 power shell 命令执行批处理文件

powershell.exe -Command "invoke-command -computername testmachinename -credential testcred -scriptblock {start-process c:\test\test.bat -ArgumentList "Arg1", "Arg2"}"

而 test.bat 看起来像

echo %time% "Started" >> C:\test\Log.txt 2>&1

set arg1=%1
set arg2=%2

echo arg1 %arg1%  >> C:\test\Log.txt 2>&1
echo arg2 %arg2%  >> C:\test\Log.txt 2>&1

cd C:\Test\

start cmd.exe
start C:\Dev\Anaconda3\python.exe test.py >> C:\test\Log.txt 2>&1

回声和集合工作正常。但是在执行 cmd.exe 或 python.exe 时,它​​什么也不做。

当我从远程机器上的命令行手动运行批处理文件时,它工作正常。

我错过了什么吗?

标签: pythonpowershellbatch-file

解决方案


推荐阅读