Forum Discussion

kavansays's avatar
kavansays
Contributor
10 years ago

Running Windows Batch Files in Test Complete(VBscript)

I am trying to execute bat file through code instead of using "TESTED APPS" as below..

 

--------------

sAutoAppPath = "E:\AutomationDir\Applications\InDMSApp_QA\bin\start_dms.bat"

Call Sys.OleObject("WScript.Shell").Run(sAutoAppPath )

and

Call Win32API.WinExec(sAutoAppPath, SW_SHOW)

--------------------------------------------------------------

WHile executing the above code i am finding error "System cannot find the file specified"

 

Can anyone please suggest the solution to execute the Bat file through the code?

 

Thanks in Advance.. :)

Kavan.. 

  • kavansays's avatar
    kavansays
    10 years ago

    Thanks All,

    Finally i got the solution on this..

     

    Sys.OleObject("WScript.Shell").Run "C:\Windows\notepad.exe", SW_SHOWNORMAL
    Win32API.WinExec "C:\Windows\notepad.exe", SW_SHOWNORMAL

     

    Above are the two ways working fine for me, problem i observed is the parenthesis and the syntax error which was not covered under error/warning that i was getting from testcomplete. 

     

    Cheers !!

  • cunderw's avatar
    cunderw
    Community Hero

    In your path string replace all of the "\"s with "\\". "\" is an escape character. 

    • kavansays's avatar
      kavansays
      Contributor

      Tried as suggested but still facing same issue..

       

      Please check attached screenshot if i have missed any..

      • TanyaYatskovska's avatar
        TanyaYatskovska
        SmartBear Alumni (Retired)

        Hi,

        You need to use & for the string concatenation in VBScript:

        Call Sys.OleObject("Wscript.Shell").Run(sAutoAppPath & "\" & "start_dms.bat")