From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

URGENT!!! How we read stdout directly?

With System Exec we can use window command line to execute an application, but I would like to read what is going on after executing that command, because the application will response by using stdout to show its information.

 

Can we read stdout directly (without using a trick to read from a text file from the source file fprintf)?

 

Thank to any help

0 Kudos
Message 1 of 8
(14,436 Views)

off the top of my head, the system exec has an option for "wait  until completed", when this is set to True you can put an indicator on its (sys exec) output and read what normalling the stdout. Otherwise when "wait till completed" is false your command is fire and forget.

 

There is a catch, this will only work if your app output to the dos window (stdout) as this is not always true...

0 Kudos
Message 2 of 8
(14,410 Views)

The standard output output of System Exec will only be updated once that function ends. I believe the user wants to be able to monitor stdout while the program that's being called by System Exec is still running. There's no direct way of doing this. A file is the way it's usually done.

 

This question has come up before, numerous times. In a previous post from a while ago JoeLabVIEW commented that he had some code to do it, but I've never seen it. 

0 Kudos
Message 3 of 8
(14,383 Views)

Since this question is likely to come up again in the near future (it's inevitable), I decided to take a second look at this. A 30-second (literally) search on Google suggested a method to use the Windows API functions to effectively perform a "Select All->Copy" command on the command window to copy the window's context to the clipboard and then simply read the clipboard. I've put together an example that illustrates this method. The original example performed a loop to iterate through the menus to find the index corresponding to the "Edit" menu. I empirically determined this and simply used a constant. Unless you've been messing around with the command window's menus I don't think this will change. The example (in 8.2) is attached. To test this just open up a command window and enter the name of the window (probably "C:\Windows\system32\cmd.exe" ) on the front panel string control.

 

Note: Due to a bug in 8.2 you cannot wire the error cluster through from one Call Library Function Node to another. If you're using a newer version of LabVIEW you should be OK and you should wire the error cluster through.

Message Edited by smercurio_fc on 11-02-2008 11:34 AM
Message Edited by smercurio_fc on 11-02-2008 11:35 AM
Message 4 of 8
(14,361 Views)

Thank for the tip, I will try it! Smiley Happy

 

 

Message 5 of 8
(14,326 Views)

I appreciate the .zip & your method, it does not need to modify the source program

 

Thanks Smiley Happy Smiley Happy Smiley Happy

0 Kudos
Message 6 of 8
(14,321 Views)

When using the System Exec and the "wait until function is complete" is True, it (system exec) ends (VI passes data out) once there is output to the standard out... it is the programmer responsibilty to loop back and "system exec" another command to the stdin (usually the cmd.exe line). This works like a fire once and get a message back. It does not fire command, read stdout, fire command again, read stdout, etc etc...

 

If your application doesn't take commands from the cmd.exe or command.com line well this may not work...

0 Kudos
Message 7 of 8
(14,305 Views)
That's a very good point. You can try to cheat by essentially launching a command window and then pasting the command that you want to run. In this way the command window gets updated and you can read it using the method I had shown above. As in the attached example. The batch file that gets run just spits out a few wait commands.
Message 8 of 8
(14,284 Views)