Ask a Question

How to Execute command line utilities from within a testcomplete script

sowmya_bs
Contributor

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 8
sowmya_bs
Contributor

RE: How to Execute command line utilities from within a testcomplete script

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



Thanks
Pavel_1
Contributor

RE: How to Execute command line utilities from within a testcomplete script

Hi


You can use WshShell.Run method to run any command line utility and save its return value to variable




WshShell = Sys.OleObject("WScript.Shell");


Result  = WshShell.Run("YourUtility.exe");



Here's more information about using this method http://msdn.microsoft.com/en-us/library/d5fk67ky(v=VS.85).aspx

RE: How to Execute command line utilities from within a testcomplete script

Hi,


I recommend that you also see the 'Testing Console Applications' help topic - it contains sample scripts:

http://www.automatedqa.com/support/viewarticle.aspx?aid=16559


Best regards,
Alexey

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
sastowe
Super Contributor

RE: How to Execute command line utilities from within a testcomplete script

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

RE: How to Execute command line utilities from within a testcomplete script


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);

  }





Best regards,
Alexey

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
surya_suggests
New Contributor

Re: RE: How to Execute command line utilities from within a testcomplete script

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

surya_suggests
New Contributor

Re: RE: How to Execute command line utilities from within a testcomplete script

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);

Bipin
New Contributor

Re: How to Execute command line utilities from within a testcomplete script

// 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]");
}

cancel
Showing results for 
Search instead for 
Did you mean: