0
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 is supossed to create a file named errorlevel.py.

The debugger does not show any errors so the file is being opened, but it doesn't create a file.

I have tried using subprocess but didn't work either.

Inside the batch file there is :

@tasklist | find /i "WinRAR.exe"
@echo h = %errorlevel% > errorlevel.py
4
  • And what is inside your TaskFinder.bat then ? Commented May 9, 2020 at 17:43
  • @shotgunner I edited the post, you can check it now Commented May 9, 2020 at 17:56
  • You should probably just directly call find /i winrar.exe using e.g. subprocess.call(..., shell=True). Commented May 9, 2020 at 17:56
  • @AKX I basically wanna find if a task is open or not. If I use tasklist | find /i "WinRAR.exe" I find the task, then with %errorlevel% I either get 0 if the task is open or 1 if the task is not. I wanna get that value into a variable in a python file so I can use it for my python project. If there's a better way to check if a task is open or not, please let me know Commented May 9, 2020 at 18:03

2 Answers 2

1

You should be able to directly use

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

instead of calling the batch script.

Even better would be not to shell out at all but use e.g. the psutil library to find the process(es) directly in Python.

Sign up to request clarification or add additional context in comments.

Comments

0

When I executed the same code it worked for me, I am using python 3, maybe this is the problem.

If it's not that I am not sure that I know why TaskFinder.bat is not opening for you a new file, but I bet it is something in the Operating System, it is probably this because it's not python.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.