Connecting Tech Pros Worldwide Help | Site Map

Redirecting the output of an exe file to a txt file

Newbie
 
Join Date: Jul 2008
Posts: 1
#1: Jul 3 '08
I am running an application on windows. I don't have the source code :(..
I need to capture the output of this exe file and redirect it into a file using my script. Can anybody help me with this? Can I use TK or IO Capture module for this?
nithinpes's Avatar
Expert
 
Join Date: Dec 2007
Posts: 400
#2: Jul 3 '08

re: Redirecting the output of an exe file to a txt file


If your exe application is directly displaying it's output to command window, use output redirection operator within system() command as in:
Expand|Select|Wrap|Line Numbers
  1. system("tool.exe >> result.txt");
  2.  
If your tool expects some user input, then you would need the display to appear both on command console as well as log file. Try using:

Expand|Select|Wrap|Line Numbers
  1. open(STDOUT, "| tee result.txt STDOUT");
  2. system("tool.exe >> result.txt");
  3. close (STDOUT) ;
  4.  
-Nithin
nithinpes's Avatar
Expert
 
Join Date: Dec 2007
Posts: 400
#3: Jul 4 '08

re: Redirecting the output of an exe file to a txt file


Quote:

Originally Posted by nithinpes

If your exe application is directly displaying it's output to command window, use output redirection operator within system() command as in:

Expand|Select|Wrap|Line Numbers
  1. system("tool.exe >> result.txt");
  2.  
If your tool expects some user input, then you would need the display to appear both on command console as well as log file. Try using:

Expand|Select|Wrap|Line Numbers
  1. open(STDOUT, "| tee result.txt");
  2. system("tool.exe >> result.txt");
  3. close (STDOUT) ;
  4.  
-Nithin

Just a correction in the second code. It should be:

Expand|Select|Wrap|Line Numbers
  1. open(STDOUT, "| tee result.txt");
  2. system("tool.exe");
  3. close (STDOUT) ;
  4.  
Reply