中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-13 06:08
47,811 topics / 349,897 posts / today 0 new / 48,256 members
DOS学习入门 & 精彩文章 (教学室) » About batch files
Printable Version  697 / 3
Floor1 chenxi Posted 2004-01-05 00:00
初级用户 Posts 2 Credits 111
I remember that after using Command to enter DOS, you can use the EXIT command to close the DOS window. But why is it that if I add the EXIT command to the end of a batch file, it still can't close the window? Other than checking "Close on exit" in the batch file's properties, is there any better way????
Floor2 Wengier Posted 2004-01-05 00:00
系统支持 Posts 10,521 Credits 27,736
Putting EXIT at the end of a batch file can be used to end the batch program, but not to close the DOS window.
Floor3 willsort Posted 2004-01-09 00:00
元老会员 Posts 1,512 Credits 4,432
Re chenxi:

Essentially speaking, exit is a DOS internal command, so it definitely cannot close the window that Windows allocates for DOS. When some people say that typing "exit" closes the window, that's only a side effect: exit first terminates the nested inner DOS shell, and only then can Windows automatically reclaim the outer DOS shell.

To put it more vividly, the outer DOS shell is the DOS window, while there can be many kinds of inner DOS shells; simply typing command nests one more shell. A typical case is that command nests a shell in order to interpret and execute a batch file, so you may see exit in some batch files, but this is not required.

The following is the explanatory text for the exit command, excerpted from the pdos6.22 help document.
----------------------------------------------------------------------------------------------------
EXIT

If the program that started the command interpreter exists, exits the MS-DOS command interpreter (COMMAND.COM)
and returns to that program.

Syntax

EXIT

----------------------------------------------------------------------------------------------------

EXIT—Notes

EXIT is for the command interpreter

When you use the MS-DOS COMMAND command to start a new command interpreter session, you can use the EXIT command to
return to the old command interpreter. Likewise, when you run certain programs, you can also run the MS-DOS
command interpreter from within the program, and then use the EXIT command to return to your program. For detailed information about the command interpreter, please
refer to the command.

If you did not use the /P (permanent) switch on the original copy of COMMAND.COM, then the EXIT command will
exit the command interpreter. After that, you must specify the location of the COMMAND.COM file at the command prompt in order to
start the command interpreter again.

Using EXIT when the command program is loaded permanently

If you started the COMMAND.COM program with the /P (permanent) switch, then EXIT will not work.
Floor4 zww3008 Posted 2004-01-09 00:00
初级用户 Posts 21 Credits 197
If you want the batch file to close automatically after it runs, just add a CLS line at the end of the batch file. Or, in the batch file's "Properties--Program", choose Minimized in the "Run" window, and check "Close on exit". After you confirm it, an MS-DOS shortcut file will be created. After that, as long as you copy this shortcut file together with the batch file of the "same name" (as long as the filename is the same; even if the path and filename specified in "Command line" do not match, it doesn't matter), you can keep those settings. Then when you double-click the batch program (if the "Command line" does not match, you cannot double-click the shortcut), it will run minimized and close automatically!
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023