Run and exec of the wscript. Shell object (the script calls other programs)

Source: Internet
Author: User
Tags pscp

Some Understandings of the differences between run and exec Methods:

The Declaration of the 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

The differences are as follows:

1. the return value of run is an integer, which is either 0 or 1 success or failure;

The Return Value of the exec method is an object. You can obtain the console output information and console error information from the returned object, that is, the stdout and stderr attributes. For example:

Set exers = objws. Exec ("pscp-r-SCP-PW .... "

Errmsg = exers. stderr. readall ()

Stdmsg = oexec. stdout. readall ()

2. The last two parameters of run, one is the CMD window style, and the other is whether the execution is waiting for completion. The last parameter is useful.ProgramAfter the statement is executed, you only need to set this parameter to true. Otherwise, the subsequent statement will run directly without waiting for the completion of the CMD window.

If you use Exec
If you want to wait for the program to run in cmd to run the following statement, you can also use the following method: oexec. stderr. readall () or oexec. stdout. readall () should also be well understood. To get the output information, it must be output only after the command is executed by CMD.

 

The following description is recorded:

Because the script you write can end normally through run or bat when calling a program, but if you use exec, the program will die after execution, there is no way to check the CPU usage time to check whether the running status ends at the right time. No reason has been found.

In recent projects, you need to use pscp In VBScript to copy files from the Linux server. The exec method is used.CodeSet exers = objws. exec ("pscp-r-SCP-PW" & password & "& loginid &" @ "& host &": "& data_path & filename &" "& windows_path)
However, during the test, when the copied file is large and the copy time is long, the CMD window will not die there, run pscp directly in the CMD window to copy the same file.
End. I couldn't find the reason, so I tried to change it to the run method. The result of the run method can end normally, but the original code had to get the console output information of CMD, while the run
It is not convenient to obtain the console information. At last, you can only redirect the console information to the file, and then the program is reading the information.

 

 

For more information about the parameters, see msdn.

Http://msdn.microsoft.com/zh-cn/library/ateytk4a (En-US, vs.85). aspx

Exec method (Windows Script Host)

Exec method (Windows Script Host ):

/*

Dim wshshell, oexec

Set wshshell = Createobject ("wscript. Shell ")

Set oexec = wshshell. Exec ("calc ")

Do While oexec. Status = 0

Wscript. Sleep 100

Loop

Wscript. Echo oexec. Status

*/

Http://msdn.microsoft.com/zh-cn/library/d5fk67ky (En-US, vs.85). aspx

Run method (Windows Script Host)

Object. Run (strcommand, [intwindowstyle], [bwaitonreturn])

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.