Forum Discussion

rlent's avatar
rlent
Contributor
15 years ago

Calling a DOS command

I am testing loading a program from a command line. I can do this by calling a batch file, but Windows 7 prompts to ask me if I really want to execute the batch file. In addition, because the path to the application varies by whether the OS is 32 or 64 bit, this doubles the number of batch files needed.



Is there a way to call DOS commands directly from Test Complete instead of using batch files?

7 Replies

  • Hi,



    The path to your application contains spaces, and it should be in quotes.

    Call Sys.OleObject("WScript.Shell").Exec("cmd /c """"C:\\Program Files (x86)\\ABC\\DEF\\App.exe"" username=a""")




    BTW, there's actually no reason to use CMD here. Try this code:

    Call Sys.OleObject("WScript.Shell").Run("""C:\\Program Files (x86)\\ABC\\DEF\\App.exe"" username=a")

  • Hi Ritesh,

     


    You've asked the same question in a separate thread here: Calling python script from Test Complete


    Let's keep the conversation there as this thread is obsolete.


     


     


    BTW, according to our Forum Rules, it's prohibited to cross post questions in different threads or to ask different unrelated questions in one thread. Your account may be blocked because of this.


    Thanks for understanding.

  • I have this line of code,  but Test Complete shows an error.



    Sys.OleObject("WScript.Shell").Exec("cmd /c """"C:\Program Files (x86)\Path\App.exe"" username=xyz applet=\""parameter\""""")







  • Ok, this works:

    Call Sys.OleObject("WScript.Shell").Exec("cmd /c ""C:\\Program Files (x86)\\ABC\\DEF\\App.exe""")



     


    but this does not



    Call Sys.OleObject("WScript.Shell").Exec("cmd /c ""C:\\Program Files (x86)\\ABC\\DEF\\App.exe username=a""")


  • Ok, this works:



    Call Sys.OleObject("WScript.Shell").Run("""C:\\Program Files (x86)\\Acme Inc\\Anvil\\Anvil.exe"" username=a password=q")




    But this does not:




    Call Sys.OleObject("WScript.Shell").Run("""C:\\Program Files (x86)\\Acme Inc\\Anvil\\Anvil.exe"" Applet=\""

    This Applet\"" username=a password=q")




    The Applet parameter can have spaces in it, that seems to be the problem


  • AlexKaras's avatar
    AlexKaras
    Icon for Champion Level 2 rankChampion Level 2
    Hi Robert,



    You did not mention the language you are using, so I assume VBScript and it seems to me that the problem is with the slashes for the Applet parameter (VBScript does not support sequences like \n, \r, etc.).

    So, instead of

    Call
    Sys.OleObject("WScript.Shell").Run("""C:\\Program Files (x86)\\Acme
    Inc\\Anvil\\Anvil.exe"" Applet=\""This Applet\"" username=a password=q")




    I would try

    Call
    Sys.OleObject("WScript.Shell").Run("""C:\Program Files (x86)\Acme
    Inc\Anvil\Anvil.exe"" Applet=""This Applet"" username=a password=q")

  • Hi



    I am looking to call python script from Test complete. Is this possible?



    I tried this but didn't worked out for me.



    Sys.OleObject("WScript.Shell").Run("C:\\Python27\\python.exe C:\\myfile.py");



    I tried to execute a sample python script via TestComplete. This script generates a .txt file.



    My python file: test.py

    Path where it is placed: C:\\

    Output of this python file: test.txt



    I placed this test.py file in C:\ and then used below function in TestComplete:



    Sys.OleObject("WScript.Shell").Run("C:\\Python27\\python.exe C:\\test.py");



    But the output file test.txt didn't get generated.



    Please advice.



    If this is not possible this way, then can I call a python script from a jscript?

    Means that, this jscript will be called into the test complete which in turns finally call that python script.



    is this possible?



    If still not, is there any other possible way?





    Looking forward to someones reply.





    Regards,

    Ritesh Chauhan