LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Writing to an already open system exec DOS window

Solved!
Go to solution

I am working on a project where I am controlling a LabSat 2 GPS generator. The unit came with an already compiled C# program that gets run from the command line. I am using the system exec vi to run the command and this then starts the LabSat 2 transmitting. Other devices are also started and the test runs. 

 

The problem I am having is if the user wants to stop the test at any point, I need to stop the LabSat2 transmitting. The way to do this is to send a Ctrl+C to the already open DOS window. In my sample program to test this, I start the LabSat 2, wait 5 seconds and then try stop it. When I write cmd /c to a new system exec vi, it opens a new DOS window and then closes it. 

 

Is there any way to write the CTRL+C command to a window that is already open, one that was opened ealrier in the program and is still running?

 

Any help would be greatly appreciated. I am attaching my vi to explain what better what I am trying to do. This vi is only to get the idea working and then I will add it to the rest of my project. 

 

Regards,

Greg

0 Kudos
Message 1 of 9
(5,922 Views)

Hi Greg,

 

As a first thought for your question, what i feel is in order to not to display the command window popping up when you write /c to new system exec, change the run minimised option to "true".

 

 

LV 8.0, 8.6, 2011,2012,2013 WinXP
0 Kudos
Message 2 of 9
(5,911 Views)

Thanks for the advice but that doesn't make a difference. 

0 Kudos
Message 3 of 9
(5,907 Views)
Solution
Accepted by topic author GregPayne

Passing the Ctrl+C command to an already opened C# Dos executable is possible using the WIN APIs. You need to get the Window Handle, then use attach console from kernel32.dll. Once you do this, you would need to explore Keyboard Input functions from MSDN, wherein you would get the command to send the Key Combination you are looking for.

Use Call Library Function nodes to call into the WINAPI Dlls.

 

 

-FraggerFox!
Certified LabVIEW Architect, Certified TestStand Developer
"What you think today is what you live tomorrow"
0 Kudos
Message 4 of 9
(5,904 Views)

Thanks for the help. I got it working by using user32.dll to get the window to the front and then again using user32.dll i send the required keyboard inputs. 

 

Thanks again

 

Message 5 of 9
(5,897 Views)

Hi,

 

How do you write into DOS window? Any tip help. My labview version is 10

Thanks,

Ott

0 Kudos
Message 6 of 9
(5,809 Views)

@Ott wrote:

Hi,

 

How do you write into DOS window? Any tip help. My labview version is 10

Thanks,

Ott


Please do not create the same question in multiple places. Stick to your original post and have some patience.

0 Kudos
Message 7 of 9
(5,793 Views)

Hi

 

I am facing the problem, what you faced regarding command window.

 

I have to run a java applicaiton on command and should terminate using ctrl+c after few minutes.  Can you please share me the details how you achieved this funcationality. Also please share the code if possible.

 

Rgds

 

Kris

0 Kudos
Message 8 of 9
(5,096 Views)

Hi Kris,

 

I wrote two blog posts a while back that might help. The first link shows how to make the window active and then the second link shows how to simulate keyboard presses which would be applied to the open window.

 

http://www.labvolution.com/labview-making-a-window-active/

http://www.labvolution.com/labview-simulating-keyboard-events/

 

There is a link at the bottom of each post where you can download the code.

 

I hope this help. If you are still stuck I can try look in to it a bit more. 

 

Greg

0 Kudos
Message 9 of 9
(5,057 Views)