Solved

Console I/O, Running External .exe commands - Help

Posted on 1997-08-04
2
208 Views
Last Modified: 2010-04-04
I am using Delphi 2, after upgrading from Delphi.

1. How do you handle console input/output (there used to be a wincrt unit)?

2. How do you call an external "command line" program from within a delphi
2 program?  

3. Can you retrieve error code from a called module in this fashion?

Thanks for your comments/examples.

-Joe.
0
Comment
Question by:jmangal
2 Comments
 
LVL 1

Accepted Solution

by:
buemoh earned 50 total points
ID: 1340509
ad 1.
in Delphi 2.x you can build consol applications with the compiler directive {$APPTYPE Console}. Afterwards you can use the buildin routines write, writeln, read, readln for console input and output.
Otherwise you can open the StdIn and StdOut via filehandles, like this:

var
  i_StdOut : integer;
  Written : integer;

begin
  i_StdOut := GetStdHandle ( STD_OUTPUT_HANDLE ) ;
  FileWrite( i_StdOut, 'This is a test', length( 'This is a test' ), Written, nil );
  CloseHandle( i_StdOut );
end;

See more about this in the ONLINE helpfiles of Delphi.


ad 2.
You can either use WINEXEC or CREATEPROCESS to start external programs. The comandline can be read with the routine PARAMSTR( parameternumber ), like this:

{ read all commandline arguments and send it to StdOut  }
for counter:=1 to ParamCount do
  writeln( PARAMSTR( counter ) );

If you need more details and some code, please e-mail.


ad 3.
If you call an external program with WINAPI then you can also get the errorcodes of this programs, but generally you can use the WINAPI call GETLASTERROR to find out the last errorcode.

This answer is quit short, but I hope this is what you want, if not, drop it away. More details can be discussed via e-mail.

Bye

Hartwig

-----------------------------------------------------------
///\\\ Hartwig MOTAL ///\\\  e-mail: moh@bue.magwien.gv.at
 Weinberggasse 60/9/7, A-1190  Vienna/Austria/Europe

0
 

Author Comment

by:jmangal
ID: 1340510
I sent you an email message.  I would like to see a code sample if possible as the online help stuff seems to be in C?..

Thanks.  -Joe.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question