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
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...
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.
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.
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...