Forum Discussion

sowmya_bs's avatar
sowmya_bs
Contributor
14 years ago

How to Execute command line utilities from within a testcomplete script

Hi..

Can anyone please let me know on how to execute the command line utilities from within a testcomplete script file and read the data from that. Immediate reply is appreciated 



-Thanks

Sowmya BS

8 Replies


  • Hello Stephanie,





    You can use the second approach from the mentioned article. The code below executes the ipconfig command and posts the contents of the command prompt window to the test log line by line:







      var p, w, txt, cnt, i, s;

      p = Sys.Process("cmd");

      w = p.Window("ConsoleWindowClass", "*");

      w.Keys("ipconfig [Enter]");

      txt = w.wText;

      aqString.ListSeparator = "\r\n";

      cnt = aqString.GetListLength(txt);

      for (i = 0; i < cnt; i++)

      {

        s = aqString.GetListItem(txt, i);

        Log.Message(s);

      }




  • Can anyone please reply on this. Its an urgent requirement.



    Thanks
    • surya_suggests's avatar
      surya_suggests
      New Contributor

      Sys.OleObject("WScript.Shell").Run("C:\\Windows\\system32\\cmd.exe");

      var p=Sys.Process("cmd");

      w=p.Window("ConsoleWindowClass","*");
      w.Keys("dir  [Enter]");

       

      aqUtils.Delay(5000);

      w.Close(3000);

    • surya_suggests's avatar
      surya_suggests
      New Contributor

      var cmd1=Sys.OleObject("WScript.Shell").Run("C:\\Windows\\system32\\cmd.exe");

  • sastowe's avatar
    sastowe
    Super Contributor
    Is there any way to have the window that the command line is executed in not close so that we can see whatever is going on? Thanks



    S
  • Bipin's avatar
    Bipin
    New Contributor

    // above method worked but I had find all cmd processes since I had multiple cmd processes running in my system
    function executeCmd(){
              Sys.OleObject("WScript.Shell").Run("C:\\Windows\\system32\\cmd.exe");
              var obj = Sys.FindAll("ProcessName","cmd",2).toArray();
              Log.Message("Total number of cmd processes in my system"+obj.length);
             p = Sys.FindChild("Name", 'Process("cmd",'+(parseInt(obj.length)+1)+')')
             w=p.Window("ConsoleWindowClass","*");
             w.Keys("dir [Enter]");
    }