LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

What is the best practice for using system exec

Solved!
Go to solution

Hello All,

I need to run an external program in order to begin a certain test,

What is the best practice for running the system exec, bearing in mind that I want to kill the task after a certain time out.

I have tried using sequence structure, but the labview will not advance to the next frame unless the program is closed manually, 

I want to use the kill task and close the external program after a certain time out.

Thanks!

Gil,

0 Kudos
Message 1 of 5
(1,617 Views)

Does the program return data that you care about (i.e. via StdOut?).

 

If you set the CMD execution to be non-blocking, you can kill it using something like "taskkill", but you'd also need the Process ID using something like "tasklist".

However, setting the SysExec node to be non-blocking prevents it returning the StdOut output.

 

If you want to keep that, but allow cancelling the task (and you don't have some other method to cancel the task) you'd have to asynchronously launch a VI in LabVIEW to call the SysExec node, and then separately kill the task (as above) if the VI doesn't return before some timeout value.

By "some other method", I mean if the task you're calling allows interruption via something like TCP server, WCF messaging, etc.

 


GCentral
0 Kudos
Message 2 of 5
(1,585 Views)

Hi,

Thanks for you reply.

I understood the second part about using an asychronous VI to kill the task.

Can you please help me understand the first part of you answer, mostly:

"setting the SysExec node to be non-blocking prevents it returning the StdOut output."

Thanks!

Gil,

0 Kudos
Message 3 of 5
(1,561 Views)
Solution
Accepted by topic author GilMaor

Sure - there's an input on the top of the SysExec node that's labelled "wait until completion? (T)".

If you wire a false value to that, then the node returns immediately, which would allow you to then continue execution in the same VI, and optionally do other things (like kill the task) some time later.

However, you lose information about when the task finishes - which makes it harder to use in your situation (I suspect).

 

The detailed help page has the following explanation:

If wait until completion? is TRUE, standard input is available as input to the command and standard output and standard error are available when the command finishes running. If FALSE, the command runs in the background and its input and output are not available. 

GCentral
0 Kudos
Message 4 of 5
(1,558 Views)

Ok your reply, is much appreciated! I will not lose any data since the other application only creates a file which I can read later in my vi.

Thanks!

Gil,

0 Kudos
Message 5 of 5
(1,553 Views)