Batch IF .exe is running, IF not start it

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/wangbingfengf98/article/details/102692288
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 programcommand or batch script (opens in a new window.) Syntax START "title" [/D path] [options] "command" [parametersKeytitle Text for the CMD window title bar (required.) path Starting directorycommand The commandbatch file or executable program to runparameters 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

2. https://ss64.com/nt/start.html

3. https://www.robvanderwoude.com/findstr.php

猜你喜欢

转载自blog.csdn.net/wangbingfengf98/article/details/102692288