In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the "what are the advantages of batch processing parsed by wsh" related knowledge, in the actual case of the operation process, many people will encounter such a dilemma, and then let the editor lead you to learn how to deal with these situations! I hope you can read it carefully and be able to achieve something!
Sample batch: test.bat
Code:
The copy code is as follows:
: On Error Resume Next
Sub bat
Echo off & cls
Echo Batching_codez_here_following_vbs_rules & pause
Start wscript-e:vbs "% ~ f0"
Exit Sub
End Sub
MsgBox "This is vbs"
The above code skillfully makes use of the syntax features of bat and vbs, so that the same file is recognized by cmd.exe as a batch, so that wscrpt.exe recognizes as vbs, and conforms to the syntax of both, and ensures that there are no errors, ensuring a high degree of compatibility between the two. Call it bat/vbs compound programming (Hybird Programming).
Give a rough explanation of the code
: On Error Resume Next
Cmd.exe is recognized as a comment
Wscript.exe recognizes that it represents a branch in vbs syntax, and then On Error Resume Next, that is, asks WSH to ignore some errors.
Reference:
Start wscript-e:vbs "% ~ f0"
Cmd.exe is recognized as: start wscript.exe, and its parameters are:
①-e:vbs setting to parse the file itself in vbs
② "% ~ f0" refers to the batch itself.
Wscript.exe recognizes this as: call a function called start, whose argument is the variable wscript, and then subtract e from the result of this function. And then there's another: branch, and then another call to a function called vbs, with the argument to the character "% ~ f0".
This sentence is the most ingenious because it successfully got the vbs engine to interpret a batch without errors! Of course, these start () and vbs () functions do not exist, but they are executed by cmd.exe as commands. Why not use wscript / / e:vbs "% ~ f0" to execute? Vbs parsing will make mistakes, hehe
The core idea of this code has been introduced. Next, in order for the batch to exit immediately after calling itself with vbs, we need exit or goto: eof, but goto call exit is another keyword in vbs, so we can only use exit sub that conforms to vbs syntax, so we add one in the second sentence
Sub bat, in fact, cmd.exe is looking for a command called sub.exe, but this command does not exist, cmd.exe skips. Then add an exit sub and end sub to the 6 and 7 sentences to let the batch end, while conforming to the syntax of vbs
That echo off & cls batch means @ echo off, but vbs doesn't recognize the @ symbol, so change it to echo off & cls, and vbs can be parsed to call a function called echo () with the argument off & cls, which is the addition of the two strings off and cls.
Well, next, you are free to write vbs scripts in batches, which are as efficient as the real vbs!
The advantage of this code is that there is no need to generate temporary files. Its practical echo or more or find to generate temporary vbs is a waste of system resources, with this code I wrote, it is completely free of these troubles. Direct mixed programming, to start wscript-e:vbs "% ~ f0" as the limit, write batch above, write vbs below, parallel!
If you have better ideas, you can discuss them with us.
=
Allyesno:% ~ fI-extends% I to a fully qualified pathname
In addition, if you use shell, you also need to use echo to write vbs. In this case, there is no saving system resources, unless copy con can write it, then just write any script file.
This is the end of the content of "what are the advantages of letting batch processing be parsed by wsh". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.