From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I capture and pass output messages from launched exe program back to CVI ?

I am trying to write an interface to a Microchip Promate 2 eprom programmer. Microchip provides procmd.exe to send commands in a DOS environment (i.e. load files, verify, program, etc). Then it returns status messages which end up in the launched DOS window. I need to capture the messages and pass them back to the CVI environment and process them to display on the main panel.
0 Kudos
Message 1 of 4
(3,251 Views)
By using DOS re-direction of I/O, you can store all the messages in a file, and read them from the file after the DOS program ends.
If your normal command is
procmd x y z
re-direct the I/O to a file by using
procmd x y z > msgfile.txt
msgfile.txt will be a text file containing any messages that procmd normally displays on the screen.
When redirecting I/O, a single > creates a new file or overwrites an existing file. >> appends to an existing file (or creates a file if the filename didn't exist).
Before you attempt to read the file in your CVI program, make sure the launched application is complete: system() waits for the command to exit; LaunchExecutable() doesn't wait.
0 Kudos
Message 2 of 4
(3,251 Views)
I think it is more complex than this.

Just like this person's problem, I also needed something where I can
re-directed I/O to my CVI program. The problem is that you need to re-direct
both input & output to your DOS program in such a way that you can send
commands to already running DOS exe from your CVI program and capture
response coming back (as they come, not after the fact) and display them on
your CVI screen or do something based on the response.

If it was just that I send bunch of commands in a batch mode and looked at
the output when the DOS program finished, it is easy, like you said, by
using files. But most of time when people are asked to put CVI on top on a
DOS program, they need to control it interactively, just like some one was
sitting there, typing these commands and looking at the reponses.

Now Tcl/Expect is really good with this as it let's you get a handle to a
process and you just read/write to it, like a file. You get events if there
is some output. I had put this question earlier and someone had replied
about a VC++ library to do this. Here is that info. I haven't tried it
myself yet.

*****************************
Al Stevens created a C++ class to do this called ConsoleApp and described
how it
works in Oct '02 DDJ.
It uses the Win32 API call CreateProcess which let you substitute your own
file
handles for the console app's stdin and stdout.

You can download the original code from here:
http://www.ddj.com/ftp/2002/2002_10/cpro1002.zip

The latest updates can be found here:
http://www.alstevens.com/quincy.html

Nick

*****************************


vishi

"Al S" wrote in message
news:50650000000500000035D30000-1042324653000@exchange.ni.com...
> By using DOS re-direction of I/O, you can store all the messages in a
> file, and read them from the file after the DOS program ends.
> If your normal command is
> procmd x y z
> re-direct the I/O to a file by using
> procmd x y z > msgfile.txt
> msgfile.txt will be a text file containing any messages that procmd
> normally displays on the screen.
> When redirecting I/O, a single > creates a new file or overwrites an
> existing file. >> appends to an existing file (or creates a file if
> the filename didn't exist).
> Before you attempt to read the file in your CVI program, make sure the
> launched application is complete: system() waits for the command to
> exit; LaunchExecutable() doesn't wait.
0 Kudos
Message 3 of 4
(3,251 Views)
Good point! And good reference to ConsoleApp!
I might have over-simplified the question. The DOS program user interface isn't described in the question: I assumed that it simply driven by command line parameters passed to the exe. It may be that after you start the program, the program has its own command prompt and you can enter multiple commands in one session. As you mentioned, if that's the case, the program needs input and output. You can use re-direction of I/O for both input (< to read commands from a file) and output (> or >> to write output to a file), but only if you know all the commands you want to send before you start the program. You can't use DOS re-direction of I/O in an interactive way.
Your point is well taken. DOS re-direction
of I/O is simple, but not very flexible and not at all interactive.
Thanks.
0 Kudos
Message 4 of 4
(3,251 Views)