Forum Discussion

Anupa's avatar
Anupa
Occasional Contributor
15 years ago

Passing Commands in Command prompt using VB Script

Hi,


I am using TestComplete version 5.15.561.7. Language used is VB Script.


I am automating one test case where in it opens the Command prompt --> changes the directroy to where office 2007 is installed --> and then opening one saved Excel workbook


For example: Call Command_Prompt_Window.Keys("c:[Enter]cd C:\Program Files\Microsoft Office\Office12[Enter]\Excel.Exe ""D:\BookMark.xlsx""[Enter]")


where Command_Prompt_Window = NameMapping.Sys.Process("cmd").Window("ConsoleWindowClass", "*")


While playbacking the script, the data passed as ("c:[Enter]cd C:\Program Files\Microsoft Office\Office12[Enter]\Excel.Exe ""D:\BookMark.xlsx""[Enter]" is not taken properly.

For example Colon(:) gets typed as ">" and quotes get typed as "@"in the Command Prompt editor


Can any one please tell me how do I automate the script using VB script so that the Colon and the quotes are entered properly in Command Prompt when the script is play back?


Regards,

Anupa


19 Replies

  • Hi Anupa,


    It looks like something is generally wrong with your environment. The following script works perfectly for me (BTW, the script just inserts the command and does not make it be executed as it happens in your case):




    Sys.Process("cmd").Window("ConsoleWindowClass", "C:\WINDOWS\system32\cmd.exe", 1).Keys("~ ep")


    BTW, the Excel issue you mentioned earlier can be possibly caused by your add-in. I recommend that you check whether the strange behavior can be reproduced: 1) without TestComplete; 2) on another machine.


    As a workaround, try using the script mentioned earlier (the one provided in the Testing Console Applications help topic) - it works with the standard input/output streams of the console window directly.

  • Anupa's avatar
    Anupa
    Occasional Contributor
    Hi Allen,



    Thanks a lot for your findings and suggestions.



    I will go through the topic you have mentioned for "Testing Console Applications" .



    Also, will try to investigate more on the issue appearing at my end with respect to 'Edit -- Paste ("~ ep")' operation in Command Prompt.



    Thanks and Regards,

    Anupa
  • Hey..you can try the sendkeys method in VBScript.  I had used it in my scripts and it works almost everytime.  I did not have command prompt cases though.  You can try it.


    set WshShell = Wscript.CreateObject.("Wscript.Shell")

    WshShell.Run("cmd")

    WshShell.Sendkeys("your run cmd")


  • Anupa's avatar
    Anupa
    Occasional Contributor
    Hi Madhi,



    Thanks a lot for your suggestion. I will try to explore more on this.



    Thanks and Regards,

    Anupa
  • Anupa's avatar
    Anupa
    Occasional Contributor
    Hi,



    I would like to thank Alex, Allen and Madhi for their valuable suggestions and taking out time for my query.



    I got the workaround for my query and have resolved the issue using Batch file.



    Thanks once again to Alex, Allen and Madhi.





    Thanks and Regards,

    Anupa

  • Hello Anupa,



    If I may suggest something.

    You may also try using Chr function to input the (:) and (").

    For colon (:), use Chr(34) and for double quote ("), use Chr(58).



    Below is a sample vbscript for using command prompt for inputting/accessing applications:



        If (Sys.Process("cmd").Exists = True) Then

            Set CmdDialog = Sys.Process("cmd")

            CmdDialog.Activate()

        Else

            Call TestedApps.Cmd.Run(1, True)

        End If

        Call Aliases.cmd.wndConsoleWindowClass.Keys("cd " + chr(34) + TestedApps.MyApp.Path + chr(34))

        Call Aliases.cmd.wndConsoleWindowClass.Keys("[Enter]")

        If (strParam <> "") Then

            Call Aliases.cmd.wndConsoleWindowClass.Keys("MyApp.exe " + strParam)

        Else

            Call Aliases.cmd.wndConsoleWindowClass.Keys("MyApp.exe")

        End If

        Call Aliases.cmd.wndConsoleWindowClass.Keys("[Enter]")

        Call Aliases.cmd.wndConsoleWindowClass.Keys("exit")

        Call Aliases.cmd.wndConsoleWindowClass.Keys("[Enter]")

        Call BuiltIn.Delay(2000)



    Note:

    I added cmd.exe in the TestedApps.





    I hope the above information may help you. :-)



    Regards,

    Ruel
  • joffre's avatar
    joffre
    Regular Contributor
    First of all, sorry for resurrecting this topic. I tried all the advices post before and nothing worked.

    I'm having a similar problem here.

    I'm working with Command Prompt and I have to type double quotes ( " ) on it.



    Here is my code:

    Call Aliases.cmd.wndConsoleWindowClass.Keys("ren "&LGComponentes&" 1.LGComponentes")


    Where LGComponentes = "01 - LG Componentes"



    The idea here is to rename the folder "01 - LG Componentes" to "1.LGComponentes", and on Command Prompt it is necessary to double quote a folder with spaces to work.



    So, any idea about how I'll make the double quotes?
  • joffre's avatar
    joffre
    Regular Contributor
    Hi Joffre,



    Just type the char twice: " should be replaced with "".



    BTW, if you need to rename a folder in TestComplete, you can use the aqFolderInfo.Rename method described in the "aqFolderInfo.Rename" (http://smartbear.com/support/viewarticle/13650/) help topic.




    Hi Allen, thanks for your support.

    I did that and it worked. About the help topic, I'll take a look on it and see if it will be interesting for me to apply on my project.



    Again, thanks.