Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 1997-08-04
2
Medium Priority
?
217 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

604 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