Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize preprocessing in batch processing

2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly shows you "how to achieve pretreatment in batch processing", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to achieve preprocessing in batch processing" this article.

First, what on earth should be done in the pretreatment?

According to my experience, the preprocessing is to replace the value of variables and deal with special symbols. Which operation should be performed first? I think we should replace the value of the variable first. There are three reasons:

1. Logically speaking

Set var=2&echo var%

For sentences like this, if we do special symbol processing first, we must first deal with the symbol "&", and "&" is used to connect two commands, so the line should be understood as two sentences. So why do we need variable delay? This is supposed to be

First assign a value to the variable var, and then handle the special symbol "&".

2. Judging from the running results

The code is as follows:

@ echo off

Set var= ^ ^ >

Echo var%

Pause

This sentence "set var= ^ ^ >" will also be preprocessed first. After preprocessing, the value of var is "^ >".

The output of this example is ">", so it can be proved that the system replaces the value of the variable with "^ >" before processing the special symbol "^".

3. From the perspective of variable substitution

The code is as follows:

@ echo off

Set ^ & var=hero

Echo% & var%

Pause

Result: display "hero"

This also shows that the replacement of variables precedes the processing of special symbols.

Second, how is the preprocessing carried out after the variable delay is started?

My view is like this: if there is an English exclamation point in the sentence "!" It will be preprocessed twice, and in other cases, it will still be preprocessed once. As the character is special, I would like to write a few examples with the help of this symbol.

(1)

The code is as follows:

@ echo off

Echo! ^ >

Setlocal enabledelayedexpansion

Echo! ^ >

Pause

The results of the two echo statements are different. Let's do some analysis:

For the first echo statement, the variable delay is not turned on, and the sentence is preprocessed to "echo! ^ ^ >" during preprocessing, which is the result of the output. Thus it can be seen that the pretreatment was carried out only once.

For the second echo statement, the variable is delayed to start because of the "!" Yes, first do a preprocessing to get "echo! ^ >", and then get "echo ^ >". The result is the same.

The exclamation mark is not output because the variable delay is turned on and the exclamation mark becomes a special symbol.

(2)

The code is as follows:

@ echo off

Setlocal enabledelayedexpansion

Set var=hero

Echo! var!

Pause

Like "echo! var!" here. Not that it has not been preprocessed, but that it has been pretreated twice. Take a look at the following code to understand.

The code is as follows:

@ echo off

Setlocal enabledelayedexpansion

Set var=hero

Echo! var! ^ >

Pause

The result of the run is: "finish ^ >". Let's analyze that during the first preprocessing, because of "! var!", the special symbol is processed without replacing the variable value, and after the processing, it becomes "echo! var! ^ >"; then the preprocessing is performed again.

It's time to replace "! var!" Yes, and after processing it, it becomes "echo customers ^ >".

(III)

Let's take a look at the situation where there is no English exclamation mark in the statement when the variable is delayed.

The code is as follows:

@ echo off

Echo ^ >

Setlocal enabledelayedexpansion

Echo ^ >

Pause

@ echo off

Set var=hero

Echo% var% ^ >

Setlocal enabledelayedexpansion

Echo% var% ^ >

Pause

How is it? that is to say, if there is no "!" There will be no second treatment.

(4)

For! Type, the processing of special symbols is done before variable substitution.

For example,

The code is as follows:

@ echo off

Setlocal enabledelayedexpansion

Set ^ & var=hero

Echo! & var!

Pause

The result of running this code is wrong.

For example,

The code is as follows:

@ echo off

Setlocal enabledelayedexpansion

Set var= ^ &

Echo! var!

Pause

The result of this code is correct.

(5)

Since we all have to deal with symbols, then%% and! Could the symbol processing of type B be the same process?

The examples in (a) are already illustrative, but I still have examples to prove.

For example,

The code is as follows:

@ echo off

Echo "^"!

Setlocal enabledelayedexpansion

Echo "^"!

Pause

For type%, the delimited characters between double quotation marks are not processed during symbol processing, but for!! Type An is the opposite.

III. Some problems raised by call

(1)

Call and runaway characters

For example,

The code is as follows:

@ echo off

Set / p var=

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report