Author Topic: RunWait VBS  (Read 2514 times)

0 Members and 1 Guest are viewing this topic.

pedroantonio123

  • Guest
RunWait VBS
« on: September 30, 2014, 04:57:42 AM »
Hi

i need some help with the code runexewait.
the Lips should wait until the VBS script is finished.


VBS Script: the VBA script is constantly changing and is generated by Lisp
and should hide the GUI of the doingsomethingforalongtime.exe

Set ShellWSH = CreateObject("WScript.Shell")
ShellWSH.Run "doingsomethingforalongtime.exe -thismaychange -andalso --input-file file.txt --output-file fileo.txt", 0, True
Set ShellWSH = Nothing


LISP: for EXE but not working for VBS

(defun runexewait (exefile extension / sys exec start)
   (if
      (and
         (setq exefile (findfile exefile))
         (setq sys (vlax-get-or-create-object "WScript.Shell"))
         (setq exec (vlax-invoke-method sys 'exec (strcat exefile extension)))
      )
      (progn
            (while
                  (equal (vlax-get-property exec 'status) 0))
                  (vlax-release-object exec)
                  (vlax-release-object sys)
                  (setq    sys nil
                        exec nil
                  )
      )
   )
exefile
)

Thanks

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: RunWait VBS
« Reply #1 on: October 02, 2014, 02:33:22 AM »
Have you tried the WCScript.Shell's Run method instead of Exec? It has an optional argument for "WaitOnReturn":
http://msdn.microsoft.com/en-us/library/d5fk67ky(v=vs.84).aspx

BTW, your code is going to release the link to the running instance the first time it gets to that while loop. Shouldn't you rather compare it to 1 instead? At least that's my understanding of the Status property:
http://msdn.microsoft.com/en-us/library/443b45a5(v=vs.84).aspx
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: RunWait VBS
« Reply #2 on: October 02, 2014, 03:52:21 AM »
Have you tried the WCScript.Shell's Run method instead of Exec?
The OP is using that method in the temporary VBS file. I don't understand the logic behind this VBS file as opposed to performing the same task directly from Lisp.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: RunWait VBS
« Reply #3 on: October 02, 2014, 05:36:11 AM »
The OP is using that method in the temporary VBS file. I don't understand the logic behind this VBS file as opposed to performing the same task directly from Lisp.
True! It would also make it a lot simpler - no need for a loop, since it simply then returns when complete.

Though the VBS environment does have the WScript.Sleep idea so it can "wait" for something to complete. Instead of the way Lisp does by constantly checking though a loop, i.e. hogging one CPU core for the entire time just simply to test if the script has completed. So I'd suggest doing it the other way round: place the Run call in Lisp and the Exec in VBS. Of course if such even makes sense.

It might help if the OP describes what is actually expected. E.g. is Exec used because access is needed to something like StdOut / StdIn? Why then command-line arguments for the input and output files?
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.