?
Solved

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

Posted on 1997-08-04
2
Medium Priority
?
213 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Accepted Solution

by:
buemoh earned 200 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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

800 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