In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "how to understand batch and VBS_JS mixed compilation". In daily operation, I believe many people have doubts about how to understand batch processing and VBS_JS mixed compilation. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts of "how to understand batch processing and VBS_JS mixed compilation". Next, please follow the editor to study!
Let's take VBS as an example to look at this method in detail.
'& Cls&@Echo off&Start "" Wscript-Nologo-E:Vbscript "% ~ 0" Msgbox "Hello,world!"
If you save the above example as Bat or Cmd run, and then save it as Vbs or Vbe run, will the result be the same?
If you have tested it yourself, you will find that when saving as a batch file (extension Bat or Vbs), the above code will flash the CMD window first, then pop up MessageBox; and save as Vbs or Vbe will directly pop up the MessageBox window (when the default host of Wsh is Cscript, accompanied by the emergence of the CMD window, the author defaults that the reader of the article is already familiar with the difference between Wscript host and Cscript, so I won't repeat it here).
Let's interpret these commands. Http://www.0391yy.com/
Line1:
If the extension is named Vbs or Vbe, it is ignored by the interpreter as a comment
If the extension is named Bat or Cmd, it is resolved to four commands, as follows:
'Cls@Echo offStart'"Wscript-Nologo-E:Vbscript"% ~ 0 "
When executing the first command, an error was reported because the 'command could not be found. However, Cmd's special error handling mechanism urges it to ignore errors and continue to execute.
When the second command is executed, the command echo and error messages on the screen are cleared.
When the third command is executed, the echo is turned off.
When you get to the fourth command, open a new Wscript.EXE script host and force yourself to run as Vbscript.
Line2:
If the extension is named Vbs or Vbe, the MsgBox process is executed.
If the extension is named Bat or Cmd, it reports an error because the Msgbox command cannot be found and exits because there are no instructions to execute.
The above two lines can also be reduced to one line, as follows:
Msgbox "Hello,world!" & Cls&@Echo off&Start "Wscript-Nologo-E:Vbscript"% ~ 0 "
Such a line of code can also be executed normally, and the principle will not be repeated.
Or we are just self-willed and split into multiple lines:
Msgbox "Hello,world!" & Cls&@Echo off 2 > Nul 3 > Nul'&Start "" Wscript-Nologo-E:Vbscript "% ~ 0"
Of course, such code can be executed normally, but some sharp-eyed readers may notice that the second line of @ Echo off is followed by a 2 > Nul 3 > Nul. What does that mean? In fact, it is to mask the error echo screen so as to ensure that the normal echo is not separated by the error echo.
To learn more about the meaning of 2 > Nul 3 > Nul, read the pervasive redirection.
Seeing this, I believe the reader has already understood the principle of the annotation mixed method.
So, the reader may ask, what if Vbs and Bat are going to interact?
In fact, it is also feasible.
Look at the following sample code:
Execute Wscript.Arguments (0)'& Cls&@Echo off 2 > nul 3 > nul'&Echo I'm Bat'&Pause'&Cscript-nologo-E:Vbscript "% ~ 0" Func1Sub Func1 Msgbox "I'm Vbs" End Sub'&Echo my Bat is back'& Set / p str= enter a string:'& For / f% an in ('Cscript-Nologo-E:Vbscript "% ~ 0" Strlen wsh.Arguments (1) ""% Str% ") Do Set / A strlen=%% ASub Strlen (String) Wscript.Echo Len (String) End Sub'&Echo the length of the string you entered is% Strlen%. & the end of the Echo demonstration & Pause
Need to be saved to run as a batch.
The flow of the above code is to execute from top to bottom, and of course the Vbs statement can be placed later, but it is interlaced for readability.
Let's read it:
Line1: the first line, with both batch commands and Vbs statements. The Vbs statement means to dynamically execute the first parameter that the Vbs receives (that is, the first parameter is executed as the statement).
Line2&3: batch command.
Line4: batch statement, call itself as VBS, and execute the VBS statement: Func1.
* * Line5&6&7:**Vbs statement to define Func1.
Line8&9: batch command, echo, set variables.
Line10: batch statement that executes the Vbs statement "Strlen wsh.Arguments (1)" and passes the batch's Str variable to the second parameter, and then gets its echo.
Line11&12&13: defines the Strlen function.
Line14&15: batch command.
At this point, the study on "how to understand batch and VBS_JS mixing" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.