China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-05 05:48
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Help: About the prompt of not finding the batch processing View 2,124 Replies 15
Floor 16 Posted 2007-06-28 09:29 ·  中国 山西 运城 联通
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
Some examples of batch self-deletion were discussed before.

Because that error is prompted when the cmd deletes the file and then reads the file again.

So adding 2>nul after del is not useful.

The simplest is to use cmd /k to restart a new cmd session.

Naturally, the error in the original session is discarded.

This sentence is applicable to dos and cmd:
%comspec% /k del %0

There can be the following changes in cmd
%comspec% /k del "%~0" /a /f 2>nul

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

Another extreme method is

First, shield the output of the standard error device and then delete.

Use ctty nul under dos
Use cd. 2>nul 3>nul under cmd

But its side effects are also very large.

The current environment in dos no longer processes any input and output.
The system is in a pseudo-dead state.
So it is usually used for the situation where all operations are completed in the batch processing and then restart directly.

In cmd, all subsequent errors in the current session are not output.
So generally, a new cmd session needs to be opened to run the batch processing and then exit this session.
--------------------------------------------------------------

Other methods have also been discussed.

But I can't remember clearly.
Probably also using auxiliary batches or other scripts
Forum Jump: