[Lazarus] GUI Front-end to Windows console application???

Sven Barth pascaldragon at googlemail.com
Thu Jan 13 22:02:32 CET 2011


On 13.01.2011 21:47, Bo Berglund wrote:
> I need to build a GUI application, which should act as a simple-to-use
> front-end to a Windows console program.
> The console program accepts a number of different commands, which are
> specified on its command line as parameters separated by spaces.
> When the console program is started with these parameters it performs
> its task and then exits.
>
> The command line parameters are rather complex and this is why I would
> like to build the GUI application in Delphi7 so I can present a
> comfortable view of it.
>
> So now I need it to do the following:
>
> 1) Run the console program with the given parameters.
>
> 2) Read back the output of the console program (it will be printed in
> the console).
>
> 3) Detect when the console program asks something and let the user
> read this in the GUI app and then respond to it by typing in the GUI.
>
> In the past (Using Delphi) and for other reasons I created a few
> helpers which I called ExecStart and ExecWait. Both of these starts a
> program, but the Wait variation also waits until the program exits.
> I used CreateProcess to start the program and WaitForSingleObject to
> check if it finished OK using its handle.
>
> So with ExecStart I can start a program with command line parameters
> all right, but how do I pick up the data printed to the console by the
> program while it runs?
>
> And how do I enter new input that the program may require when it does
> not finish execution?
>
> Any pointers to how this can be done appreciated.
>
>

You could use TProcess for this (found in unit "process").

It's documentation is here:
http://www.freepascal.org/docs-html/fcl/process/tprocess.html

And on the Wiki are examples for using it:
http://wiki.lazarus.freepascal.org/Executing_External_Programs

I hope this helps you further (if not feel free to ask, of coures :) ).

Regards,
Sven




More information about the Lazarus mailing list