LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Close execution of .exe started with SystemExec


@V.Life wrote:

Out of Labview I managed to open and close the prompt window using PowerShell. Can I use the SystemExec block to launch it and execute the same commands that I tried out of Labview? Thanks.


If you would like to kill your application with PowerShell like

Get-Process | Where-Object { $_.Path -like "*MyProgram.exe" } | Stop-Process -Force

then save it as PowerShell script like KillApp.ps1, then call it from LabVIEW like

powershell.exe -ExecutionPolicy Bypass -File "Your\Path\To\KillApp.ps1"

That is:

snippet.png

 

0 Kudos
Message 11 of 17
(145 Views)

Is it possible also to open the application with PowerShell? Thanks

0 Kudos
Message 12 of 17
(135 Views)

@V.Life wrote:

Is it possible also to open the application with PowerShell? Thanks


Yes, of course, something like that:

Start-Process "<YOUR PATH TO PROGRAM>\MyProgram.exe" -ArgumentList "arg1"

 

0 Kudos
Message 13 of 17
(119 Views)

I managed to execute the script to open the .exe file but it is executed in the black window, not in the window of Power Shell, so I can't close it with the script of closure.

0 Kudos
Message 14 of 17
(85 Views)

@V.Life wrote:

I managed to execute the script to open the .exe file but it is executed in the black window, not in the window of Power Shell, so I can't close it with the script of closure.


Do not confuse the PowerShell window with the console window. If you want to receive output from a console application in PowerShell, you need to run it as follows:

& "C:\Path\To\MyProgram.exe" arg1

 

0 Kudos
Message 15 of 17
(69 Views)

@V.Life wrote:

I need to close the execution of MyProgram.exe after a fixed time.


Maybe I'm missing something, but when you call the program, can't you pass in an argument (or if the "fixed time" stays the same, build it into MyProgram) so that MyProgram simply stops itself after "a fixed time"?

 

If the "fixed time" isn't really "fixed", another method that seems less complicated and less reliant on PowerShell or other OS-specific stuff is to have MyProgram look for a "Suicide" file in an easily-accessible Data location, say once/second.  If it finds it, it deletes it and then exits.  Now all the Master program needs to do is to create the "Go Quit" file in the right location, and MyProgram should stop within a second (as I've written this example).

 

Note you'd want a different "Quit" routine for each "MyProgram" (and, also obviously, a unique "MyProgram" for each "Master" routine).

 

Bob Schor

0 Kudos
Message 16 of 17
(47 Views)

@V.Life wrote:

This VI is missing "PostMessage Master.vi".


I provided a link in my previous post, where you can download the library.

 

George Zou
0 Kudos
Message 17 of 17
(37 Views)