X
X
Xaip2018-04-05 10:12:55
Python
Xaip, 2018-04-05 10:12:55

Python run and then check the status of a bat file?

I'm trying to run the bat file and check its performance on the server, but I just can't enter the condition correctly.

import psutil
import time
import os
from psutil import Popen


procname = 'conhost.exe'
list = []
for proc in psutil.process_iter():
    pinfo = proc.as_dict(attrs=['pid', 'name'])
    list.append(pinfo['name'])
while(1):
    if not list == procname:
        os.startfile('file.bat')
        time.sleep(10)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
timur102, 2018-04-05
@Xaip

import psutil
import time 
import os
while 1:
    items = [c.name() for c in psutil.process_iter()]
    
    if "conhost.exe" not in items:
        os.startfile('file.bat')
        time.sleep(10)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question