Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Capturing output from an .exe file

Status
Not open for further replies.

pilg

Programmer
Feb 16, 2001
82
0
0
GB
I have an exe file which I run from my code, I was wondering whether it is possible to capture the output from that exe file (everything it displays in the dos box) and store in a variable, then write it to a file. has anyone got any ideas I just need everything this exe file prints to the screen to go into a file.
 
Lets See if this work,
System("C:\\MeyExecs\\track.exe > xyz.dat");


Hope that Helps,
Regards,
SwapSawe.s-)
 
My explanations are quite long but my Enlish is not
so good, please understand me.

Some programs, for example gcc for win32 (cygnus gcc),
doesn't work for '>'.

You can redirect standard input or output or other
file handles by using dup2.
For example, following code redirects standard output
to a file handle 'fd'.

dup2( fd, 1 );

If you executes a program after above is processed,
its output is stored to the file. Another tip is
that, when you develop your program for Windows GUI
platform, you need to consider this platform doesn't
have standard output so above method doesn't directly
work. The way(trick) to solve this problem is:

1. make a win32 console mode program to capture a
program output using dup2 by executing a requested
program.

2. Launch the program you made for 1 in the GUI
mode application.

So the GUI application executes the console mode
program you made and the console mode program
actually executes the program you wanted to execute
and captures its output. Needed informations are
transferred using program arguments and program
can be waited by wait(unix) or WaitForSingleObject(win32).

I think this method is used in UltraEditor for Win32.

To capture the output of a program interactively,
you need to use pipe. Refer to documents for Unix
pipes or Win32 pipe programming. It is more complex
than dup2.
Hee S. Chung
heesc@netian.com
 
Hi,

I think the answer from SwapSawe is correct. Try,

<exe name> > <output filename>

Hope this will help you.

hsk007 :cool:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top