Jump to content
Macro Express Forums

External Script very slow

Recommended Posts

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...