Page 1 of 1
SOLVED Run vbscript as non-blocking operation?
Posted: Wed Jun 08, 2011 8:39 pm
by SteveTX
I have a vbscript that takes 60 seconds to complete. I currently send the command that does the vbscript using "send to me". However, the do as vbscript seems to run as a blocking operation, subsequently returning Non-Responsive status to windows explorer for the application if i click on the card while it is running.
Is there a way to run the vbscript as a non-blocking operation, or so that my card doesn't return NR status, without exec wscript + write to file?
Re: Run vbscript as non-blocking operation?
Posted: Wed Jun 08, 2011 10:33 pm
by Mark
Hi Steve,
Why "without exec wscript + write to file" ? I don't think there is a solution that doesn't include writing the VBScript to a file.
Kind regards,
Mark
Re: Run vbscript as non-blocking operation?
Posted: Wed Jun 08, 2011 11:26 pm
by SteveTX
because I am generating code and the process i want to make multithread using an asunchronous queue. writing operations would slow down an threaded operation.
Re: Run vbscript as non-blocking operation?
Posted: Wed Jun 08, 2011 11:35 pm
by Mark
Hi Steve,
The choice is between 1) executing a script with the do command every 60 seconds and 2) writing the script to a file and executing it every... 500 milliseconds if necessary. This makes me think that the slow-down isn't much of an issue.
Kind regards,
Mark
Re: Run vbscript as non-blocking operation?
Posted: Wed Jun 08, 2011 11:49 pm
by SteveTX
Mark,
The slowdown becomes an issue when you need to run more than 1 script per minute.
I need to run up to 1200 threads if that is the case.
Steve
Re: Run vbscript as non-blocking operation?
Posted: Thu Jun 09, 2011 12:06 am
by Mark
Hi Steve,
You have to run up to 1200 threads if you have to run more than 1 script per minute but you don't know this yet???
You started with 1 cycle per minute en writing files lets you run 120 cycles per minute. That's an improvement already.
So, what is your goal? To run the VBScript 1200 times a minute? Perhaps you should try to find a different solution. Something like AutoIt might receive parameters from LiveCode through a socket and execute your VBScript with those parameters, for example.
Kind regards,
Mark
Re: Run vbscript as non-blocking operation?
Posted: Sat Jun 11, 2011 9:27 pm
by SteveTX
Accepted Solution
Code: Select all
set the hideConsoleWindows to true
set shellCommand to "cmd.exe"
...
put "cscript.exe //nologo" && quote & vbscriptFile & quote into theCMD
open process theCMD
And we didn't even have to use "Start". However, there are some limits here. Getting an asynchronous return code and processing it ought to be fun.

Re: SOLVED Run vbscript as non-blocking operation?
Posted: Sat Jun 11, 2011 9:40 pm
by Mark
So, you decided to write to file anyway, Steve?
Mark
Re: SOLVED Run vbscript as non-blocking operation?
Posted: Sun Jun 12, 2011 2:24 am
by SteveTX
Yup. Runrev file operations appear to be fast enough to support it for now. When we start hitting caching issues, i'll randomize the filename. If it gets past that point, i'll have to use a socket and custom binary for wsh interface.
Re: SOLVED Run vbscript as non-blocking operation?
Posted: Thu Jun 16, 2011 5:42 am
by SteveTX
Strange behavior of open process, however. Open process seems to work, but after a few hundred or thousand executions, even when paced, open process seems to hang. I have watched the open process action attempt to execute the command given (to open cscript), but fails to actually start the executable according to the task manager.
I am unable to account for this strange behavior yet, too bad there is no stack trace for runrev. I'll investigate with reading from the processes.
Re: SOLVED Run vbscript as non-blocking operation?
Posted: Thu Jun 16, 2011 9:44 am
by Mark
Hi,
You might want to kill old processes at some point. The error might also be in your VBScript, of course. You need to include correct error handling and make sure that it quits properly regardless of whether it could execute completely.
Kind regards,
Mark
Re: SOLVED Run vbscript as non-blocking operation?
Posted: Fri Jun 17, 2011 3:44 am
by SteveTX
Found the issue: file operations are NOT fast enough. Once i started randomizing the filenames and processing the process output (via Mike's non-blocking read from process code), i found that cscript was not reading the contents of the file into memory before livecode was processing "delete tempFile". So we were getting file not found errors from cscript. So I reordered deletion of tempFile to the beginning of the command, as it loops.
To solve the problem:
Code: Select all
global tempFile
on execTask
... bla bla operations ...
delete file tempFile // delete previous command
put specialFolderPath("Temporary") & "/macro" & random(999) & ".vbs" into tempFile //randomize the filename to avoid caching issues.
open file tempFile for write
write macroScriptFile to file tempFile
close file tempFile
wait 100 milliseconds
put "cscript.exe //nologo //X" && quote & tempFile & quote into theCMD
open process theCMD for read
send "readProcess" to me in 3 seconds
put empty into macroScriptFile // clear out what was stored in macroString
end execTask
on readProcess
read from process theCMD for 100 lines in 100 millisecs //mark's code was missing a 'for' statement
if the result is "time out" then
send readProcess to me in 0 millisecs
else
close process "theCMD"
end if
put it into procOutput
if procOutput is not empty then debugLog " Execution Error: " & procOutput
end readProcess