python - 当我打开一个应该用 python 创建另一个文件的批处理文件时,python 会打开它但它不会创建文件
问题描述
import os
import time
def FindTask():
while True:
os.startfile('C:\\Users\\Joze\\Desktop\\League Bot\\TaskFinder.bat')
time.sleep(2)
from errorlevel import h
if h == 0:
print("is")
elif h == 1:
print("no")
FindTask()
TaskFinder.bat
应该创建一个名为errorlevel.py
.
调试器没有显示任何错误,因此文件正在打开,但它不会创建文件。
我试过使用subprocess
但也没有工作。
在批处理文件中有:
@tasklist | find /i "WinRAR.exe"
@echo h = %errorlevel% > errorlevel.py
解决方案
你应该可以直接使用
cp = subprocess.run('tasklist | find /i "WinRAR.exe"', shell=True)
print(cp.returncode)
而不是调用批处理脚本。
更好的办法是根本不使用,而是使用例如psutil库直接在 Python 中查找进程。
推荐阅读
- android - Android扩展EditText在画布上绘制超出范围
- c# - Unity raycast 可能的错误?
- python - django:按字母顺序对表格数据进行排序
- ios - CollectionView 自动调整大小标签不起作用
- machine-learning - 通过自定义 LSTM 时的形状错误
- react-native - eslint 将文本推送到编辑器的开头
- python - 用python中的数值模型拟合曲线
- html - 如何在此文本上设置填充或边距
- javascript - API 与 Postman 一起工作,但在 Javascript Fetch 中失败
- html - 如何使网页游戏画布适合窗口