Detect if bat file is running via double click or from cmd window

前端 未结 12 1668
醉话见心
醉话见心 2020-12-29 02:54

I have a bat file that does a bunch of things and closes the cmd window which is fine when user double clicks the bat file from explorer. But if I run the bat file from a al

12条回答
  •  轮回少年
    2020-12-29 03:32

    It's not only possible, but your desired behavior is the normal behavior of batch file execution, unless you do something 'special':

    • when executing a batch file by double-clicking it in Explorer, the cmd window will close when it's done;
    • when the batch file is executed from the command line, it simply returns to the command line prompt when complete - the window is not closed;

    So I think the question that needs to be answered is what are you doing in the batch file that causes the command window to close when you execute it by the command line?

提交回复
热议问题