How do I launch an external App. ??

Posted on 1998-04-03
Last Modified: 2010-04-06
How do I launch an external Application from D2.0 and wait for it to end (just like system() does in C/C++) ??
A little more information : the Application is a DOS based one, so it receives some parameters from command line and creates some output files.

I'm sure this is a very simple question, just want to know what **function or procedure** to call from inside my D2.0 app.

Besides, does anybody (expert I mean) know how many lines a Memo can store, depends on the TMemo implementation or on the amount of memory available on the system ??

thanx. Rigansen.
Question by:rigansen
  • 4

Accepted Solution

Edo082297 earned 40 total points
ID: 1361263
Hi Rigansen,

function CreateProcessSimple(sExecutableFilePath : string):string;
  pi: TProcessInformation;
  si: TStartupInfo;
  FillMemory( @si, sizeof( si ), 0 );
  si.cb := sizeof( si );

  CreateProcess( Nil,    PChar( sExecutableFilePath ),   Nil, Nil, False,   NORMAL_PRIORITY_CLASS, Nil, Nil,  si, pi );

  // "after calling code" such as
  // the code to wait until the
  // process is done should go here  

  CloseHandle( pi.hProcess );
  CloseHandle( pi.hThread );
Now, all you have to do is call CreateProcessSimple(), let's say to run Windows' Notepad:
CreateProcessSimple( 'notepad' );      

It's that... simple.




Expert Comment

ID: 1361264
I believe that the TMemo component has a (theoretical) limit of 2 gigabytes! The operating system will limit the number of characters the user can enter if memory limit has been reached.

Expert Comment

ID: 1361265
Hi again and sorry, I'm not paying attention to the question you asked. To get the Delphi to wait for the process to end, use


You have to load the process handle (hProcess) into the ProcessInfo structure when you use CreateProcess.


Author Comment

ID: 1361266

what about using WinExec() ?

what about executing a .BAT file ?

can you help me on that ??

Expert Comment

ID: 1361267
Hi Rigansen

   Sorry for not getting back sooner, I only happened to notice you asked for more info when reviewing another question!
   WinExec is implemented as a call to CreateProcess, and yes, you can use it. However, it remains only for backwards compatibility, and this means that you should only use CreateProcess. Besides, it allows you more control over the process.
   About the .BAT file, you'll have to post :) My DOS is limited (ironically) and since M$ took the help file out, I really can't tell you - the only BAT files I write are to do update files across networks and the likes (simple copies, etc...).


Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi - replicating a form 8 66
Delphi XE10 Round Image 2 79
Delphi Firemonkey Need Sample for Online Shopping Example. 2 120
Find and Replace Stream with 0s 8 57
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…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

863 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

25 Experts available now in Live!

Get 1:1 Help Now