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
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
