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