Solved

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

Posted on 1997-08-04
2
192 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

759 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now