QTP provides an interface called the automation object model. This model is essentially a COM interface providing a bunch of objects that can be used to automate QTP. The full object list is available in the QuickTest Professional Automation documentation.
Running QTP tests from the command line is useful for doing scheduled automatic testing. If you use a continuous integration system to do automatic builds of your software, you can run your QTP tests on the latest build.
The following is a Python script that is able to run a test and print out Passed or Failed. It is a direct port of example code in the documentation written in VBScript
1import win32com, win32com.client23qtp = win32com.client.Dispatch("QuickTest.Application")45# starts up QTP6qtp.Launch()78# make the QTP window visible9qtp.Visible = True1011# Open a test, replace the path12qtp.Open("C:\Tests\test1")1314# to open a QTP test in Quality Center15# qtp.Open(r"[QualityCenter] Subject\FolderName\QTPScript")1617# create a RunResultsOptions object18qtResultsOpt = win32com.client.Dispatch("QuickTest.RunResultsOptions")1920# set the location to where the results will be save21qtResultsOpt.ResultsLocation = "C:\Test\test1\res"2223qtp.Test.Run(qtResultsOpt)2425print "Test has %s" %qtp.Test.LastRunResults.Status2627# close the Test28qtp.Test.Close()2930# quit QTP31qtp.Quit()