Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming

How to determine the output of a console application

By Zarko Gajic, About.com

When you write a console mode application (no GUI), the output by default goes to the screen, but this can be overridden by the process starting the app (see: How to capture the output from a console mode application).

Use the code below to find where the output is going:

~~~~~~~~~~~~~~~~~~~~~~~~~
program SampleConsoleApp;
{$APPTYPE CONSOLE}

uses
   SysUtils, Windows, Dialogs;
var
   hStdOut: THandle;
begin
   writeln('Some output') ;
   hStdOut := GetStdHandle(STD_OUTPUT_HANDLE) ;
   if hStdOut = INVALID_HANDLE_VALUE then RaiseLastOsError;

   case GetFileType(hStdOut) of
     FILE_TYPE_UNKNOWN:
       ShowMessage('Unknown output ') ;
     FILE_TYPE_DISK:
       ShowMessage('Output to a File') ;
     FILE_TYPE_CHAR:
       ShowMessage('Console output') ;
     FILE_TYPE_PIPE:
       ShowMessage('Pipe output') ;
   end;
end.

{
When this app is run "normally"
it will display a 'Console output' message.
}
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» Download a file from the Internet with progress indicator
« How to find what control was previously selected

Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming

About.com Special Features

Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. 2003 Delphi Tips
  7. How to determine the output of a console application

©2009 About.com, a part of The New York Times Company.

All rights reserved.