Tasklist command

Tasklist command

autoid374ceb4990
Collaborator Collaborator
562 Views
8 Replies
Message 1 of 9

Tasklist command

autoid374ceb4990
Collaborator
Collaborator

The "tasklist" command can be run from a command window to list the currently running processes. When used like this:   tasklist | find "blender"   it returns the name blender.exe if blender is currently active (either minimized or maximized) and also sets an errorcode that can be used to determine if the blender program is currently running.

Can the tasklist command be run from autolisp?

0 Likes
Accepted solutions (1)
563 Views
8 Replies
Replies (8)
Message 2 of 9

paullimapa
Mentor
Mentor

This lisp may not meet the exact result you want but give it a try.

(load "TaskFind")
(TaskFind "Blender.exe") 

Note: Task "Blender.exe" must match in case as listed in the Tasklist.

; TaskFind check for name of process that's running
; if found notepad opens created text file in current drawing folder
; Argument:
; img-nam = case sensitive process name to look for 
; Example:
; (taskfind "NVDisplay.Container.exe")
; (taskfind "Registry")
; OP:
; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/tasklist-command/td-p/13385903
(defun TaskFind (img-nam / fil fr exe txt)
  (vl-load-com)
  (setq fil (strcat (getvar 'dwgprefix) "MyTaskList.txt") ; save file to current dwg location
        exe (strcat "Tasklist.exe | find \"" img-nam "\" > " fil)
        txt (strcat "Notepad.exe " fil)
  )
  (if (findfile fil) ; chk if file exists
    (vl-file-delete fil) ; delete file
  )
  (command "_Sh" exe) ; shell tasklist find process
  (alert (strcat "Completed Find Process on:\n" img-nam)) ; forces pause to allow for text file to be created
  (if (setq fr (open fil "r")) ; chk if txt file created
   (progn
    (if (read-line fr) ; chk if file is empty 
     (startapp txt) ; open with notepad
     (progn
      (vl-file-delete fil) ; delete file
      (alert (strcat "Process " img-nam " Not Found."))   
     )
    )
    (close fr)
   ) 
   (alert "Failed to create Text File.")
  ) ; if
  (princ)  
)

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 9

autoid374ceb4990
Collaborator
Collaborator

Thanks.  I am using R14, so visual lisp not available.

I can call the SHELL command and then run a batch file that contains:

tasklist | find "blender"
if errorlevel 0 SET FOUND="YES"
if errorlevel 1 SET FOUND="NO"

 

Then check the FOUND variable to see if blender is active.

 

0 Likes
Message 4 of 9

paullimapa
Mentor
Mentor

Wow, are you running R14 on Window 2000?

Also just out of curiosity, does this revised version run inside R14:

; TaskFindr14 version check for name of process that's running
; if found notepad opens created text file in current drawing folder
; Argument:
; img-nam = case sensitive process name to look for 
; Example:
; (taskfind "NVDisplay.Container.exe")
; (taskfind "Registry")
; OP:
; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/tasklist-command/td-p/13385903
(defun TaskFind (img-nam / fil fr exe txt)
;  (vl-load-com)
  (setq fil (strcat (getvar 'dwgprefix) "MyTaskList.txt") ; save file to current dwg location
        exe (strcat "Tasklist.exe | find \"" img-nam "\" > " fil)
        txt (strcat "Notepad.exe " fil)
  )
  (if (findfile fil) ; chk if file exists
;    (vl-file-delete fil) ; delete file
    (close (open fil "w")) ; empty file
  )
  
  (command "_Sh" exe) ; shell tasklist find process
  (alert (strcat "Completed Find Process on:\n" img-nam)) ; forces pause to allow for text file to be created
  (if (setq fr (open fil "r")) ; chk if txt file created
   (progn
    (if (read-line fr) ; chk if file is empty 
;     (startapp txt) ; open with notepad
      (command "_Sh" txt)  
     (progn
;    (vl-file-delete fil) ; delete file
      (close (open fil "w")) ; empty file
      (alert (strcat "Process " img-nam " Not Found."))   
     )
    )
    (close fr)
   ) 
   (alert "Failed to create Text File.")
  ) ; if
  (princ)  
)

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 5 of 9

Sea-Haven
Mentor
Mentor

Is this not part of your response to another post about switch to another program window ? Switch focus to another program - Autodesk Community

0 Likes
Message 6 of 9

autoid374ceb4990
Collaborator
Collaborator

paullimapa

Yes, I am running R14 on 64 bit Windows 7 and Windows 10.

Your file loads in R14 but what do you enter to run it?

Also no vl_ commands in my old LISP so it will not execute.

 

0 Likes
Message 7 of 9

paullimapa
Mentor
Mentor
Accepted solution

Which is why I purposedly revised it by commenting out the vl functions.

In my first reply I posted how you can run the function:

paullimapa_1-1742769389012.png

If the TaskFind function finds Blender.exe as one of the running processes in the Tasklist, the contents will be saved into the current drawing folder a text file called MyTaskList.txt and then the file will be opened for review using Notepad.

 

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 8 of 9

autoid374ceb4990
Collaborator
Collaborator

My LISP is a bit rusty, but I changed the (getvar 'dwgprefix) to (getvar "dwgprefix") in the line below and it works.

 (setq fil (strcat (getvar 'dwgprefix) "MyTaskList.txt") ; save file to current dwg location

Thanks

 

0 Likes
Message 9 of 9

paullimapa
Mentor
Mentor

Good. So back in r14 lisp days it doesn’t take the apostrophe method to retrieve system variable info. but required the good old surrounded by quotes method. 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes