TestComplete 调用powershell 和cmd并获取屏幕输出

1.Run powershell 命令并捕获屏幕输出:

function RunPowerShell()
{
 var oShell = Sys.OleObject("WScript.Shell"); // or oShell = WshShell
  var oExec = oShell.Exec("powershell -command $PSVersionTable.PSVersion.Major");
  oExec.StdIn.Close(); // Close standard input before reading output

  // Get PowerShell output
  var strOutput = oExec.StdOut.ReadAll();
  // Trim leading and trailing empty lines
  strOutput = aqString.Trim(strOutput, aqString.stAll);

  // Post PowerShell output to the test log line by line
  aqString.ListSeparator = "\r\n";
  for (var i = 0; i < aqString.GetListLength(strOutput); i++)
  {
    Log.Message(aqString.GetListItem(strOutput, i));
  }
}


2.Run cmd文件并获取屏幕输出:

function StartCMD()
{
  var dscliCmd = "Test.cmd";
  aqString.ListSeparator = "\r\n";
  if(aqFile.Exists(dscliCmd))
  {
    Sys.OleObject("WScript.Shell").Run("C:\\Windows\\system32\\cmd.exe");
    var p = Sys.Process("cmd");
    wCMD = p.Window("ConsoleWindowClass", "*");
    wCMD.Keys(dscliCmd +" [Enter]");
  }
  else
    ReportError("Can not find " + dscliCmd);
  wCMD.Close()
}


获取输出:

txt = wCMD.wText




你可能感兴趣的:(TestComplete,软件测试)