Forum Discussion

vikram_u_k's avatar
vikram_u_k
Contributor
9 years ago

How do i run a Batch file from testComplete

Hi,

  I am using TestComplete 11.31 and have found it very useful. Currently i need to send a Commandline/Batch command for a C# executable.

 

Please let us know the Insert New operation corresponding to adding a commandline/batch job execution using the process action ("cmd").

 

regards,

Vikram U

  • baxatob's avatar
    baxatob
    Community Hero

    One way is to add your batch file as a TestedApps object and run it:

     

    TestedApps.yourBatch.Run()

     

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      You could also just fire up a shell and call the Exec method.

       

      Sys.OleObject("WScript.Shell").Exec("cmd /c ""C:\MyDir\MyBat.bat""")
    • vikram_u_k's avatar
      vikram_u_k
      Contributor

      Hi Support,

      Thank you for the quick response. 

       

      I just needed a clarification on this question regards the arguments to be passed for the executable.

       

      I have a exe which i call with 2 Arguments( ex:  ABC.exe Param1  Param2). In the TestedApps i note that the ABC.exe is listed with commandline parameters as "Param1 Param2".

       

      Is there a way to change/parameterise the second argument alone(Param2)?.

       

      Thanks and with regards,

      Virkram U

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        You should be able to access the parameters using the TestedApps object.  See the reference at https://support.smartbear.com/viewarticle/75248/ for the example.

         

        Essentially, you would access the SimpleParams object of your tested app, change the parameter to only include param 2, activate, and then run your app.

  • m_essaid's avatar
    m_essaid
    Valued Contributor

    I use cmd alot now, I create environments for my apps.

     

    for example :

     

    first, I kill all cmd processes

     

    then :

     

    TestedApps.Add('cmd.exe', 'mylocation\mybatchfile.bat', 1, true, '');

    TestedApps.cmd.Run;

     

    Then I wait till the end of the batch execution with this wait procedure

     

    p := Sys.FindChild('ProcessName', 'cmd');
    while p.Exists do
    begin
    IsClosed:= p.WaitProperty('Exists', False);
    if not IsClosed then
    Delay(3000, 'I wait for the end of the files copy');
    p:= Sys.FindChild('ProcessName', 'cmd');
    end;

    • vikram_u_k's avatar
      vikram_u_k
      Contributor

      Thanks Guys,

        I saw that the approach calls for creating commandlines which create new TestedApps which can be validated early.. user inputs with command arguments can be created in advance,

       

      Edit: Is there a specific reason we have debug, profile options?.

       

      I got the Results from this Link.. https://support.smartbear.com/viewarticle/70910/

      The application "MyTestAndroid\TestedApps\TestedApp.exeArgument1  Argument2" started. 18:22:34 Normal
      Application domain created: DefaultDomain 18:22:34 Higher
      Thread Create ID: 53324 18:22:34 Higher
      Thread Create ID: 58744 18:22:34 Higher
      Module Loaded: C:\Windows\assembly\NativeImages_v4.0.30319_32\mscorlib

       

       

      Thanks a Lot guys for the Support.:heart: