简体   繁体   中英

How do I launch a non-interactive GUI from a windows 10 service written in python?

I am trying to automate running "Teststand" scripts from a Windows service. So far I've accomplished the automation by calling the following from the command prompt:

C:\Program Files (x86)\National Instruments\TestStand 2013\Bin> 
SeqEdit.exe /runEntryPoint "Single Pass" "c:\Users\pathtofile\MyTests.seq" /quit

I'm using Python, so I make this happen using the subprocess module. It opens, runs, saves results, and closes on its own. Perfect!!! However, because it launches the Teststand GUI, it won't work in a Windows service. I don't even need the GUI (because I don't touch it, and results stored in a folder), but I can't seem to run Teststand without it.

I've messed around with CreateProcessAsUser() using win32 but I can't seem to get anything to work. Can anyone offer a solution in Python that uses the command above to run a Teststand sequence from a Windows service (windows 10)???

On option could be to use the TestStand API to run the sequence using the engine directly. Here is an example from the NI Knowledge Base :

import win32com.client
tsEngine = win32com.client.Dispatch('TestStand.Engine.1')
print('TestStand %s.%s ready' % (tsEngine.MajorVersion, tsEngine.MinorVersion))
sequencePath = 'C:\\Users\\Desktop\\Sequence File 1.seq'
seqFile = tsEngine.GetSequenceFileEx(sequencePath)
execution = tsEngine.NewExecution(seqFile, "MainSequence", None, False, 0)
execution.WaitForEndEx(60000)
print(execution.ResultStatus)
tsEngine.ReleaseSequenceFileEx(seqFile, 0x4)

I have found from using this that for it to close cleanly I had to use del to clear up the references to execution and seqFile and also to handle UIMessages to ensure there are none outstanding at the end of the execution.

You might have a look at this code. It is a TestStand CLI written in C#. You can remove unnecessary code and only keep the sequence execution and return the result.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM