当我打开一个可以使用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
AKX

您应该可以直接使用

cp = subprocess.run('tasklist | find /i "WinRAR.exe"', shell=True)
print(cp.returncode)

而不是调用批处理脚本。

更好的办法是根本不花钱,而要使用psutil库直接在Python中查找进程。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章