NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Get Process ID of Process with step "call executeable"

Hello,
I call a*.exe with the step "call executeable" in teststand. The *.exe starts a process which I can see in the tasklist. I have to kill this process later if the test fails.
1. Is it possible to kill a process from teststand?
2. If not, then I want to kill the process with the windows command "taskkill. For this I need The Process ID of the running process. Is it possible to get this process ID at that time      when I start the process?
3. Are there any other possibilities to solve this problem?
 
thank you
 
 
regards samuel
 
0 Kudos
Message 1 of 4
(5,833 Views)
Samuel,

Each Call Executable step returns a ProcessHandle property that can be used to access the process.  This is slightly different than a Process ID, but if you want to kill it, the handle is good enough for you.  There is a Windows API call  TerminateProcess that will allow you to do this.  It is located in the kernel32.dll.  It takes two parameters, the first is the process handle, the second is the desired exit code for the process.  Both parameters are longs.  You can pass in the Step.ProcessHandle property from the Call Executable step and terminate the process.  Use a C/C++ DLL Action step type to do this.

Allen P.
NI

Message 2 of 4
(5,814 Views)

I tried the method mentioned but I got an error back from TestStand that says "This function does not have parameter information in the DLL or uses types not recognized by TestStand". I'm using ver. 2019. Is there a workaround for that?

0 Kudos
Message 3 of 4
(2,058 Views)

Hello,

 

I know two way of handling process. Command lines and .Net Process.

 

With command line, it is possible to query the list of the running processes using tasklist command, and to identify by name a process, in order to retrieve its ID.

 

For example :

C:\Users\me>tasklist /FI "IMAGENAME eq explorer.exe"

 

Nom de l’image PID Nom de la sessio Numéro de s Utilisation
========================= ======== ================ =========== ============
explorer.exe 6200 Console 1 202 120 Ko

 

As you may guess, I'm using a french OS with accentuated caracters. That's mainly command line parsing, that you can manager with TestStand Expression (not really funny, I agree). Note you can use the /FO parameters to format the output as a list or csv (here as cvs) :

C:\Users\me>tasklist /FI "IMAGENAME eq cmd.exe" /FO csv
"Nom de l’image","PID","Nom de la session","Numéro de session","Utilisation mémoire"
"cmd.exe","10260","Console","1","5 864 Ko"
"cmd.exe","10464","Console","1","5 864 Ko"
"cmd.exe","1876","Console","1","9 676 Ko"

 

If you have several instances of the same executable, you may want to know who is who (here, 3 times cmd.exe). Nothing impossible if you are initiating the process (check who is running, run the new process, identify the new one's PID).

 

On the other hand, you also can use .Net Process from System.Diagnostics to manage execution of another process. But you will have to manage references. I used this in LabVIEW code, JKI exposes a package for VIPM that wrapps the whole think quite nicely : JKI .NET System Exec Toolkit for LabVIEW. If you are familiar with LabVIEW, it may be a good source of inspiration to implement something using .Net adapter in TestStand.

 

Hope this helps,

Message 4 of 4
(2,028 Views)