tasklist | findstr /i "appName.exe" > nul && echo Yeah || echo Nope
The command(s) after &&
on the same line will run when findstr
found the "appName.exe"
and skip the command(s) after the ||
on the same line. Otherwise, when findstr
failed to find the "appName.exe"
, it will skip commands after &&
and execute those after ||
.
If you want multiple commands for success and/or failure:
tasklist | findstr /i "appName.exe" > nul && (
echo.Yeah
echo.It's running.
) || (
start "appName" "path\appName.exe"
)
the /i specifies that the search is not to be case-sensitive.
Start a program, command or batch script (opens in a new window.) Syntax START "title" [/D path] [options] "command" [parameters] Key: title Text for the CMD window title bar (required.) path Starting directory. command The command, batch file or executable program to run. parameters The parameters passed to the command.
note my windows is windows 10.
references:
1. https://superuser.com/questions/669964/batch-if-exe-is-not-running