Solved

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

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

729 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