LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Closing windows command line using libraries

Solved!
Go to solution

Hi there!

Im making a project that runs a executable using the windows command line. I have managed to open the command line from LabView and im able to run the executable correctly. The problem is that I want to close the command line automatically after a time when it opens. So Im trying to use "call library function node" with user32.dll library and FindWindow() and DestroyWindow() functions, because I think that I have to use this functions. Does someone know how to close the command line after a time? is it posible? am I using the correct functions?

Help please!

0 Kudos
Message 1 of 20
(2,411 Views)

Hi,

If the time before closing cmdline window is not necessary, you can set the parameter "waiting end" to false ( default value is True); See help of vi command line.

Or you can  use a .NET method to start a process in System library ( see attached snippet)
Best regards

Message 2 of 20
(2,392 Views)

What is it that you're running? Do you have the ability to change its code? I would suggest that if so, you should program it with a way to receive an instruction to close/quit.

 

Assuming that you can't change the program you're calling, and that you're opening it with Run Minimized as the default False, and Wait until Complete as False (probably - although if you're asynchronously launching the SysExec, there's no reason it has to be false), and there are no command line strings you can pass to the executable to instruct it to end after some time, then I think you're probably right to use the functions you're talking about.

 

On my system (64bit Win 10 Pro) the FindWindow is either FindWindowA or FindWindowW according to ANSI or Unicode. I think you'll have better luck with FindWindowA in LabVIEW, but I'm ready to be corrected.

 

You can pass it two constant C Str inputs and receive (for me) a U64 output. However, trying to close my Block Diagram window with the DestroyWindow(handle) function killed LabVIEW. It might be better if you actually own the window you're killing - the Microsoft documentation cautions that you can't destroy a window you didn't create.


GCentral
0 Kudos
Message 3 of 20
(2,378 Views)

if I put The parameter "wait until end" false, I cant get the "standard output" information and I need it, and I need to close the command line automatically without clicking by hand, so I think "whait until end" parameter cannot do nothing to close it automatically. do yo know a way to close a window automatically on an easy way?

0 Kudos
Message 4 of 20
(2,376 Views)

Im running a speech recognition toolkit live using the command line, and the recognised words appear in the command line, so I need the standard output information. No i cant change the code of the executable. And yes I have put the "run minimized" parameter as false and "wait until end" to true, because I need to have the standard output information to work with it.

The problem is that running system exec vi whith the parameter whait until end as true, I cant see what is happening in the command line, and the information generated on the command line is inputed to the standard output string only when I close the command line, so I need to close it after a time (when it has made a recognition) and then close it to take the information to the standard output.

Yes the functions Im using also are FindWindowA and destroy window, can you give me a explanation of the parameters you used and what are you writtin in that parameters, because I have read Help information and other forums but Im not abble to close the command line

0 Kudos
Message 5 of 20
(2,369 Views)

Certainly:

 

Example_VI_BD.png

 

I disabled the DestroyWindow(..) call. You can try with that - good luck 😉

I sent "NULL" as the class type, this matches everything. "Untitled 7 Block Diagram" was the window I thought I could close, but it crashed LabVIEW when I enabled the DestroyWindow frame. Perhaps you'll just crash the executable you want to kill 🙂


GCentral
0 Kudos
Message 6 of 20
(2,365 Views)

Hi,

Why not using the solution of this item

http://forums.ni.com/t5/LabVIEW/NET-Process-STDOUT-STDIN-Interface-to-CLI-application/m-p/3648650#M1...

Using the reference of the process, you can close it after. Count the number of lines will be used to close the process.

Best regards.

0 Kudos
Message 7 of 20
(2,353 Views)

Thanks! I will try it!

0 Kudos
Message 8 of 20
(2,341 Views)

So I am guessing you want to close a window that is running a process before that process is completed.

Because you can set a boolean on the systemexec.vi to automatically close the window after the process exits.

 

What I have done in the past is use the taskkill command with the systemexec.vi 

 

I have a program that builds a batch file line to launch Iperf in a console window and call the batch file with the systemexec.vi.

Launch.png

Yeah it's not pretty making a snippet messed it up a bit...

 

Anyway the part I want you to see is I set the window title of the Iperf window with the "title Client" line in the batch file. This is important as you will see below. Run the snippet and look at the created temp.bat

 

To kill the running Iperf I use the taskkill command, notice that taskkill need the window title of the task you are killing. 

tkill.png

That says taskkill /FI "windowtitle eq Client*"

 

The only caveat I have ran into is taskkill can not kill a task that is ran as Administrator, seemingly even if my executable is ran as Administrator. I am guessing even if the LabVIEW executable is ran as Administrator, the systemexec is still running at lower privileges? So if someone has messed with Windows UAC (like I found on several machines on our lab) and set console windows to always run as Administrator, taskkill will fail.

-------------------------------------------------------------------
Unfortunately, most readers of this Forum, including some real Experts, have not mastered the skill of being able to read the code that Posters fail to post. If we cannot see "what you did wrong", we are unable to tell you how to fix it. (Bob Schor 28 August 2018)
0 Kudos
Message 9 of 20
(2,333 Views)

tkill.png

That says taskkill /FI "windowtitle eq Client*"

 


He said that his program works with the command prompt. So he should write taskkill /FI "windowtitle eq Command*" /F

0 Kudos
Message 10 of 20
(2,300 Views)