Cory Posted August 11, 2010 Report Share Posted August 11, 2010 I have a VBScript that's nearly instantaneous. But when executed from the External Script command with the Console Capture it takes a few seconds. Is this a bug? If not is there a way to make it faster? Quote Link to comment Share on other sites More sharing options...
chris Posted August 18, 2010 Report Share Posted August 18, 2010 When using the external script command, we use a function called WaitForSingleObject to query whether the process has completed. In this API call we pass a time value, which is the maximum time to wait before the function exits. We have the option of using either milliseconds or a value called INFINITE (which means the function waits indefinitely before returning control back to Macro Express). The problem with this function is that it's not 100% accurate when waiting for a process handle when using the INFINITE flag. Experience (and a lot of web searching) as shown that using the INFINITE flag while waiting for a process handle will cause the app to lockup as the API call will not return control to Macro Express. So, we coded in a 1000 millisecond wait time. If the function was not successful (meaning the process is still running), we immediately run the function again (with no delays in between except for the normal overhead caused by threads and API calls, which is on the order of microseconds, usually). In theory, the 1000 millisecond delay is an upper-limit (at least, according to Microsoft), meaning that the function will wait at most 1 second for the application to terminate . This is the only delay we have in that particular block of code. So, if you're seeing a delay, either the WaitForSingleObject API is misbehaving, or the code to read from the data stream is taking longer than it should (again, the only delay here should be the standard API overhead). Are you outputting a large amount of data through the script, or is it just a few characters? Quote Link to comment Share on other sites More sharing options...
Cory Posted August 18, 2010 Author Report Share Posted August 18, 2010 Anything from a few characters to a couple of pages. Nothing huge. The one I was playing with in this case just returned a serial date integer. What do you think about the fact that a simple VB script will execute instantly but if I enable to option to capture the console output. I also wonder if this could be related to the problem you helped me with that one day where enabling the console capture caused MEP to hang indefinitely. Of course it's most likely it was just a problem with that machine and not MEP as I couldn't reproduce the problem elsewhere. Thanks for looking into it! Quote Link to comment Share on other sites More sharing options...
chris Posted August 18, 2010 Report Share Posted August 18, 2010 It could be related. Are you running it on the same computer? Quote Link to comment Share on other sites More sharing options...
Cory Posted August 18, 2010 Author Report Share Posted August 18, 2010 I have tried it on several computers with various OSs. If one enables console capture it takes a couple seconds. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.