Forum Discussion
I am using powershell to do something very similar. I am not sure its possible to do what you want purely within a keyword test, and if it were it would probably be just easier to do in a Script Test.
Here's a functional snippet of what I'm using based from the Documentation I could find from TestComplete. Hopefully it will be easy to understand, all you should need to do is just copy and paste this into a Script Test and change the text '<your command here>' to the command you provided above. This text is in the middle of the last block of code.
I am assuming that the coding language chosen at the creation of your project was JavaScript. If it was python instead any changes should be easy to make. If it is a different language it could be a little more difficult but definitely doable.
// This function will steal the characters being output by the powershell and display them in the Details tab when the test is over/paused
// powershellObject: this is the object which holds the powershell.exe that is being used.
// endChar: this holds a text character eg. ">". The function will stop reading from the powershell's output until either it sees this character, or it reaches the end of the output.
function readTilChar(powershellObject, endChar){
var out = "";
var curChar;
while (!pwershellObj.StdOut.AtEndOfStream){
curChar = pwershellObj.StdOut.Read(1);
out += curChar;
//Log.Message(curChar)
if (curChar == endChar) break;
}
//Log.Message(out)
return out;
}
// This function will start powershell.exe, display all of the text that is autmaticaally shown in the powershell when its started, then return the object which holds the powershell
function startPowerShell(){
var powershell = WshShell.Exec("powershell.exe");
var out = readTilChar(powershell, ">");
Log.Message("PowerShell initiation complete: See the output in the Details panel of the test log", out);
return powershell
}
// This function will type the command into the terminal and begin it's execution
// powershellObject: this is the object which holds the powershell.exe that is being used.
// command: this is the command that gets run by the powershell. It needs to be of type string. (something like this: "ls")
function sendCommand(powershellObject, command){
if (powershellObject != null){
powershellObject.StdIn.Write(command + "\n")
}
}
// This function will reset the Database
function resetDatabase(){
//start the powershell
var powershell = startPowerShell()
//Enter what you want the powershell to run here within the ""
sendCommand(powershell, "<your command here>")
//This just grabs any output that would happen from your command
var output = readTilChar(powershell, ">")
//Create a log in TestComplete and put the output from your command in the Details tab
Log.Message("Database successfully reset, check Details tab for powershell output.", output)
}