Forum Discussion
- rraghvaniChampion Level 3
Late to the discussion, but there are examples shown here, https://support.smartbear.com/testcomplete/docs/reference/program-objects/wshshell/index.html
- torusContributor
Thanks rraghvani for posting the documentation pertaining to this post. For someone like myself, it helped to have the exact code example due to not fully understanding the concepts behind the WshShell command.
- MW_DidataRegular Contributor
Function RunBatch(BatFile, WaitJN) 'Run the command and wait for completion 'Parameters : File, Size&state of window, Wait for completion RunBatch= Sys.OleObject("WScript.Shell").Run ((BatFile), 1, (WaitJN)) End Function
I use this for running Batchfiles, This way I can use the (WaitJN) parameter to either wait for the batch to be done or run it while TC does other things.
EDIT: I posted the VBScript code, For JavaScript I use this one:
function RunBatch(Batfile, WaitJN) { Log.Message("Running Batchfile '" + (Batfile) + "'", ""); Sys.OleObject("WScript.Shell").Run ((Batfile), 1, (WaitJN)) }
The parameters work the same.
- torusContributor
To anyone else who comes to this discussion, MW_Didata's example is VBScript. Thanks MW_Didata for the information and example code!
- MW_DidataRegular Contributor
oops you're right, I meant to post this one
function RunBatch(Batfile, WaitJN) { Log.Message("Running Batchfile '" + (Batfile) + "'", ""); Sys.OleObject("WScript.Shell").Run ((Batfile), 1, (WaitJN)) }
- nastesterRegular Contributor
I use this:
function runBatchFile(batchFilePath) { try { var process = Sys.OleObject("WScript.Shell"); process.Run('cmd.exe /C "' + batchFilePath + '"', 1, true); while (process.Status == 0) { Delay(100); } } catch (e) { Log.Error("An error occurred while running the batch file: " + e.message); } Log.Message("Batch file executed") } var batchFilePath = Project.ConfigPath + "SmokeTestCleanup.bat";
- torusContributor
Thanks for the tip nastester. That worked great. I tried to get the cmd.exe /C <batchFile> to work for a while but was unsuccessful (I might not have been putting in the double back slashes and might have messed up where I placed the quotes). Your example works perfectly plus has error catching. Thanks for the tip!
- torusContributor
function runBatchFile()
{
WshShell.Run("C:\\Temp\\hello.bat")
}Others posted some really good alternative answers as well ...
Related Content
- 8 years ago
Recent Discussions
- 3 days ago