Redirecting the output of an exe file to a txt file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • archana1234
    New Member
    • Jul 2008
    • 1

    Redirecting the output of an exe file to a txt file

    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
    Recognized Expert Contributor
    • Dec 2007
    • 410

    #2
    If your exe application is directly displaying it's output to command window, use output redirection operator within system() command as in:
    Code:
    system("tool.exe >> result.txt");
    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:

    Code:
    open(STDOUT, "| tee result.txt STDOUT");
    system("tool.exe >> result.txt");
    close (STDOUT) ;
    -Nithin

    Comment

    • nithinpes
      Recognized Expert Contributor
      • Dec 2007
      • 410

      #3
      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:
      Code:
      system("tool.exe >> result.txt");
      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:

      Code:
      open(STDOUT, "| tee result.txt");
      system("tool.exe >> result.txt");
      close (STDOUT) ;
      -Nithin
      Just a correction in the second code. It should be:

      Code:
      open(STDOUT, "| tee result.txt");
      system("tool.exe");
      close (STDOUT) ;
      Last edited by nithinpes; Jul 4 '08, 05:20 AM. Reason: edited script

      Comment

      Working...