Forum Discussion

rlent's avatar
rlent
Contributor
14 years ago

How can I execute a DOS command from within TestComplete?

I have a tested application that I want to test loading from a command line. Right now, I call batch files to do this. This works great in XP, but in Vista and Windows 7, Windows prompts me for permission to run the batch file. So this means that if I want to run the script in Vista and Windows 7, I need to babysit the script. I've been looking through the help, and I haven't been able to find a way to make DOS calls from within TestComplete. It's probably there, I just can't find it. Any pointers? I need to be able to call the application with a number of parameters.

6 Replies


  • Hi Robert,





    To use quoted parameters, it is necessary, firstly, to add two quotation marks before the filename and after the last parameter, secondly, add the backslash symbol before and after the quoted parameter, for example:







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









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

  • I'm able to call the tested app, but I haven't figured out yet how to call it with parameters.



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



    This works, but I need to be able to use parameters, if anyone has any ideas, I would really appreciate it.
  • Actually, I can use parameters with this, but there is a problem. My tested app has some parameters that contain quotation marks. Parameters like:

     

    username=xyz

     

    work just fine. But parameters like



    applet="This applet"



    do not work. It seems that the quotation marks confuse the OS.
  • ramesh_dalavai's avatar
    ramesh_dalavai
    Occasional Contributor
    Hi Im trying to run the bellow command, i get to see a dos prompt being launched but does not run my bat file

    Im using TestComplete 10

    can someone help ?




    Sys.OleObject("WScript.Shell").Exec("cmd /c C:\\TestComplete\\JavaBinding\\ReportGenerator.BAT");


    • Bharadwaj's avatar
      Bharadwaj
      Contributor

      Hi this looks like a bug with test complete,I had a similar problem ,all i had to do is to open excel from command prompt and the command for that was 

      "C:\Program Files\Microsoft Office\Office14\excel.exe"

      but I had to fiddle with the double quotes and had to play around and finally this worked

       

      """C:\Program Files\Microsoft Office\Office14\excel.exe""""
      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        Hi,

         

        This is correct and expected behavior: Exec() command requires string parameter. So, it must be quoted. As the parameter contains spaces, it must be quoted according to the OS requirements. To make script engine treat quotes within another quotes as quotes, the inner quotes must be doubled. This gives you three quote characters at the beginning of the string and three quotes at string end. (Your second code sample contains one extra quote character at the end.)