Forum Discussion
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);
}- sowmya_bsContributorCan anyone please reply on this. Its an urgent requirement.
Thanks- surya_suggestsNew 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_suggestsNew Contributor
var cmd1=Sys.OleObject("WScript.Shell").Run("C:\\Windows\\system32\\cmd.exe");
- Pavel_1Contributor
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
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- sastoweSuper ContributorIs 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 - BipinNew 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]");
}
Related Content
Recent Discussions
- 2 days agoGane195