none
VB script Procedures order of execution RRS feed

  • Question

  • Hi

    I have 4 procedures in my vbscript code, i am calling them in the required order (like A,B,C,D etc...). But, before it completing the Procedure B, it started Procedure D and giving error stating that "path not found". Actually here, Procedure D is dependent on Procedure B completion, then only Procedure D will pass. how to overcome this problem, i tried with wscript.sleep and tried calling procedure D in the end of Procedure B, but it doesn't worked. Please help

    ProcedureA(Build_Folder)
    ProcedureB(Build_Folder)
    call ProcedureC()
    ProcedureD(Release_Folder)

    Thursday, July 2, 2015 5:39 PM

Answers

  • I agree Frederik, but my entire script is in VBScript, so i need to write it in VB script. This is the only part stopping me now :(

    In this case you need to get some VBScript practice . . .
    • Marked as answer by prabasb Friday, July 3, 2015 7:28 PM
    Friday, July 3, 2015 2:10 PM

All replies

  • The VBScript interpreter executes script code sequentially. In your pseudo-code it will run ProcedureA, complete it, then commence with ProcedureB. However, if you use the Run method within ProcedureA then ProcedureB could commence before the Run method has completed its job. It all depends on the switches you use with "Run".

    How about posting your code to illustrate your problem?

    Thursday, July 2, 2015 6:27 PM
  • Hi Frederik,

    Below is the procedure giving issue to me. It should complete first, then it's output will be used by another procedure.  Please help.

    Sub StartBuild()
    Set WshShell = wscript.CreateObject("wscript.Shell")
    WshShell.exec "cmd"
    WScript.Sleep 100
    WshShell.AppActivate "C:\Windows\system32\cmd.exe"
    WScript.Sleep 100
    wshshell.sendkeys """C:\Program Files\TortoiseSVN\bin\svn.exe"" export --force --username user --password ddd svn://16.80.15.93/trunk" & " " & Build_Folder
    wshshell.sendkeys "{ENTER}"
    WScript.Sleep 100

    CurrDir = objFSO.GetParentFolderName(WScript.ScriptFullName)
    WshShell.sendkeys "CD /d" & " " & " " & LIG_Build_Folder
    wshshell.sendkeys "{ENTER}"
    WshShell.sendkeys "svn clean install -Dtest -P sanity"
    wshshell.sendkeys "{ENTER}"
    WshShell.sendkeys "CD /d" & " " & " " & CurrDir
    wshshell.sendkeys "{ENTER}"
    Set WshShell = Nothing

    End Sub

    Thursday, July 2, 2015 6:35 PM
  • It is as I suspected. You shell out to the operating system with the "Exec" method. Use the "Run" method instead and specify the WaitOnReturn switch.

    Using the SendKeys method to execute an external file is a bad idea for these reasons:

    • The method is unreliable because you never know which window it sends its keystrokes to.
    • You have no control whatsoever about the flow of the program.
    • VBScript has its own methods to execute external commands. You know them already: "Exec" and "Run".
    Thursday, July 2, 2015 6:50 PM
  • Hi Frederik,

    Thank you, it worked. Below is my modified script. But here, it opened a different window to run the program and i need to close that window manually to continue the execution of next lines of code from my script. How to close the opend window automatically and continue the execution of the script. I tried keeping 0 insted of 1, it worked, but it doesnt continued with the execution of next lines of code.

    Set WshShell = wscript.CreateObject("wscript.Shell")
    command = "cmd /K ""C:\Program Files\TortoiseSVN\bin\svn.exe"" export --force --username user --password ddd svn://16.80.15.93/trunk" & " " & Build_Folder
    WshShell.run command, 1, true

    Thursday, July 2, 2015 7:31 PM
  • I tried keeping 0 insted of 1, it worked, but it doesnt continued with the execution of next lines of code.

    Programming by trial and error is not a good idea. Much better to check the references in order to see what the switches mean. In this case the downloadable help file script56.chm will tell you that the switch after the command (0 or 1) determines the type of window that the "run" command uses.

    If svn.exe requires the user to press Enter at the end then your script cannot get around it. It is a property of svn.exe. The following console command might do the trick:

    echo. | "C:\Program Files\TortoiseSVN\bin\svn.exe" export --force --username user --password ddd svn://16.80.15.93/trunk C:\MyBuildFolder

    A few more points:

    • Why do you use a VB Script to execute console commands? A batch file would do the same in a simpler manner.
    • Why do you invoke an extra command processor with this line?
      command = "cmd /K ""C:\Program Files\TortoiseSVN\bin\svn.exe"" export --force --username user --password ddd svn://16.80.15.93/trunk" & " " & Build_Folder
      This command is simpler and works just as well:
      command = """C:\Program Files\TortoiseSVN\bin\svn.exe"" export --force --username user --password ddd svn://16.80.15.93/trunk" & " " & Build_Folder
    • Why the /K switch with cmd.exe? It forces the command processor to remain open!

    Thursday, July 2, 2015 8:20 PM
  • Hi Frederik,

    it worked, i removed cmd option to launch svn, it worked as expected. It downloaded the source code from SVN.

    Now I neeed to put another run method to do the build. In Below "WshShell.run RunBuild, 1, true" line, i am trying to go into the folder generatred by previous run method and then issue the build command, but it is not working as expected. I think some syntax mistake i am doing, could you please help me to correct it. "LIG_Build_Folder " is a vbscript variable i need to include in the DOS command.

    Sub StartBuild()
    Set WshShell = wscript.CreateObject("wscript.Shell")
    RunSVN= """C:\Program Files\ToiseSVN\bin\svn.exe"" export svn://16.80.15.93/trunk" & " " & Build_Folder
    RunBuild= "cmd CD /d" + " " + LIG_Build_Folder & "mvn install -DskipTests -P Sanity"
    WshShell.run RunSVN, 1, true
    WshShell.run RunBuild, 1, true

    Friday, July 3, 2015 8:06 AM
  • Sub StartBuild()

    Set WshShell = wscript.CreateObject("wscript.Shell")
    RunSVN= """C:\Program Files\ToiseSVN\bin\svn.exe"" export svn://16.80.15.93/trunk" & " " & Build_Folder
    RunBuild= "cmd CD /d" + " " + LIG_Build_Folder & "mvn install -DskipTests -P Sanity"
    WshShell.run RunSVN, 1, true
    WshShell.run RunBuild, 1, true

    I mentioned before that you're punishing yourself when putting console commands into a VBScript file. This would be much simpler in a batch file:

    @echo off
    "C:\Program Files\ToiseSVN\bin\svn.exe" export svn://16.80.15.93/trunk c:\MyBuild_Folder
    runSVN.exe
    cd  /d  d:\Lig_Build_Folder
    mvn.exe install -DSkip . . .

    Friday, July 3, 2015 8:24 AM
  • I agree Frederik, but my entire script is in VBScript, so i need to write it in VB script. This is the only part stopping me now :(
    • Edited by prabasb Friday, July 3, 2015 12:44 PM
    Friday, July 3, 2015 12:43 PM
  • I agree Frederik, but my entire script is in VBScript, so i need to write it in VB script. This is the only part stopping me now :(

    In this case you need to get some VBScript practice . . .
    • Marked as answer by prabasb Friday, July 3, 2015 7:28 PM
    Friday, July 3, 2015 2:10 PM