In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces how to use run and exec of WScript.Shell objects in vbScript. It is very detailed and has a certain reference value. Friends who are interested must read it!
Set exeRs = objws.Exec ("pscp-r-scp-pw" & password & "& loginid &" @ "& host &": & data_path & fileName & "" & windows_path)
But in the test, when the copy of the file is relatively large, copy for a long time, there will be a cmd window dead there motionless situation, directly in the cmd window to run pscp copy the same file can end normally. Can not find the reason, so change to the run method to try, the result run method can end normally, but the original code need to get the console output information of cmd, and run is not convenient to get console information, and finally can only redirect the console information to the file, and then the program is reading. Finally, let's talk about some understanding of the difference between run and exec:
The declaration of these two methods is as follows
Function Exec (ByVal Command As String) As WshExec
Function Run (ByVal Command As String, [ByVal WindowStyle], [ByVal WaitOnReturn]) As Integer
You can see several differences:
1 the return value of exec run is an integer, that is, 0 or 1 success and failure, while the return value of the exec method is an object, from which console output information and console error information, such as StdOut and StdErr properties, can be obtained. For example:
Set exeRs = objws.Exec ("pscp-r-scp-pw."
ErrMsg = exeRs.StdErr.ReadAll ()
StdMsg = oExec.StdOut.ReadAll ()
You can access console errors and console messages.
The last two parameters of the cmd run, one is the style of the cmd window, and the other is whether to wait for the execution to be completed. The last parameter is very useful. If you want to wait for the end of the program executed by this cmd, after executing the statement after objws.Exec, just set this parameter to true, otherwise the later statement will not wait for the completion of the cmd window, just run it directly (our project has this requirement, after copying a file from the server to the local, we need to open the file operation immediately If you don't finish copying the file, you will make an error. ). In addition, if you use the exec method, you can also use the following method if you want to wait for the program in cmd to finish executing and then execute the following statements:
OExec.StdErr.ReadAll () or oExec.StdOut.ReadAll () should also be easy to understand. In order to get the output information, there must be an output only after the execution of cmd.
The above is all the content of the article "how to use run and exec of WScript.Shell objects in vbScript". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
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.