use .bat file to run python

target 1: run python in local machine

  1. simple
@echo off
python test.py

echo.
echo ** Please click the "X" button in the upper-right corner to close this window **
:loop
timeout /t 1 /nobreak >nul
tasklist | find "cmd.exe" >nul
if not errorlevel 1 goto loop
  1. activate conda activate
    use .bat file to run python_第1张图片

the tartget exe file is %windir%\System32\cmd.exe "/K" C:\Users\zhaib\MiniConda3\Scripts\activate.bat C:\Users\zhaib\MiniConda3,

extract C:\Users\zhaib\MiniConda3\Scripts\activate.bat C:\Users\zhaib\MiniConda3 set into the following code.

@echo off
call C:\Users\zhaib\MiniConda3\Scripts\activate.bat C:\Users\zhaib\MiniConda3
call activate env_pytorch
:: do not use call conda activate env_pytorch or call source  activate env_pytorch
python test.py 


echo.
echo ** Please click the "X" button in the upper-right corner to close this window **
:loop
timeout /t 1 /nobreak >nul
tasklist | find "cmd.exe" >nul
if not errorlevel 1 goto loop

target 2: login remote linux system to execute python code

don’t know how to implement.

others

  1. close the windows only user click the top-right x
echo.
echo ** Please click the "X" button in the upper-right corner to close this window **
:loop
timeout /t 1 /nobreak >nul
tasklist | find "cmd.exe" >nul
if not errorlevel 1 goto loop

你可能感兴趣的:(python,开发语言)