SOLVED Run vbscript as non-blocking operation?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
SteveTX
Posts: 170
Joined: Sun Jan 17, 2010 9:00 pm

SOLVED Run vbscript as non-blocking operation?

Post by SteveTX » Wed Jun 08, 2011 8:39 pm

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?
Last edited by SteveTX on Sat Jun 11, 2011 9:29 pm, edited 1 time in total.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Run vbscript as non-blocking operation?

Post by Mark » Wed Jun 08, 2011 10:33 pm

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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

SteveTX
Posts: 170
Joined: Sun Jan 17, 2010 9:00 pm

Re: Run vbscript as non-blocking operation?

Post by SteveTX » Wed Jun 08, 2011 11:26 pm

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.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Run vbscript as non-blocking operation?

Post by Mark » Wed Jun 08, 2011 11:35 pm

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
Last edited by Mark on Sat Jun 11, 2011 9:39 pm, edited 1 time in total.
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

SteveTX
Posts: 170
Joined: Sun Jan 17, 2010 9:00 pm

Re: Run vbscript as non-blocking operation?

Post by SteveTX » Wed Jun 08, 2011 11:49 pm

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

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Run vbscript as non-blocking operation?

Post by Mark » Thu Jun 09, 2011 12:06 am

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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

SteveTX
Posts: 170
Joined: Sun Jan 17, 2010 9:00 pm

Re: Run vbscript as non-blocking operation?

Post by SteveTX » Sat Jun 11, 2011 9:27 pm

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. :roll:

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: SOLVED Run vbscript as non-blocking operation?

Post by Mark » Sat Jun 11, 2011 9:40 pm

So, you decided to write to file anyway, Steve?

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

SteveTX
Posts: 170
Joined: Sun Jan 17, 2010 9:00 pm

Re: SOLVED Run vbscript as non-blocking operation?

Post by SteveTX » Sun Jun 12, 2011 2:24 am

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.

SteveTX
Posts: 170
Joined: Sun Jan 17, 2010 9:00 pm

Re: SOLVED Run vbscript as non-blocking operation?

Post by SteveTX » Thu Jun 16, 2011 5:42 am

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.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: SOLVED Run vbscript as non-blocking operation?

Post by Mark » Thu Jun 16, 2011 9:44 am

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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

SteveTX
Posts: 170
Joined: Sun Jan 17, 2010 9:00 pm

Re: SOLVED Run vbscript as non-blocking operation?

Post by SteveTX » Fri Jun 17, 2011 3:44 am

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

Post Reply