1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PID Existence And Title Checking

Discussion in 'T&T - Aliases' started by nchernoff, Jun 9, 2008.

  1. nchernoff

    nchernoff Administrator Staff Member

    Messages:
    42
    Migrated From JP Software Wiki

    Description

    These two aliases and two functions make it easy to check whether a PID exists, and if it does, what the window title is, if there is one.

    PIDExistChk

    The PIDExistChk alias tests for the existence of a PID, such as those returned by the _pid or _startpid internal variables.

    Here is how the alias may look in an alias file.

    Code:
    pidexistchk= & ^
       iff "%1" NE "" then & ^
           set pidexistchkfile=%@unique[%temp] & ^
           tasklist /o >! %pidexistchkfile & ^
           for %pidexistchkline in (@%pidexistchkfile%) do (echos. & iff "%@word[0,%pidexistchkline]" eq "%1" then echo 1 & endiff) & ^
           del /f /q %pidexistchkfile & ^
           unset pidexistchkfile & ^
       endiff
    A useful, related function is PIDExist. It returns 1 if the PID exists or 0 if it does not.

    Code:
    PIDExist=%@len[%@execstr[pidexistchk %1]]
    PIDTitleChk

    The PIDTitleChk alias works similarly, but returns the window title, if any, associated with the PID.

    Here is how the alias may look in an alias file.

    Code:
    pidtitlechk= & ^
       iff "%1" NE "" then & ^
           set pidtitlechkfile=%@unique[%temp] & ^
           tasklist /o >! %pidtitlechkfile & ^
           for %pidtitlechkline in (@%pidtitlechkfile%) do (echos. & iff "%@word[0,%pidtitlechkline]" eq "%1" then echo %@instr[24,,%pidtitlechkline] & endiff) & ^
           del /f /q %pidtitlechkfile & ^
           unset pidtitlechkfile & ^
       endiff
    A useful, related function is PIDTitle. It returns the window title if there is one for the PID.

Share This Page