Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2009-04

CTRL-Break and asynchronous exec

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Jürgen Hestermann

I am trying to port some console programs to Free-Pascal(they use the CRT unit and originaly where written for Turbo-Pascal then they were ported to Virtual-Pascal). I use "MODE OBJFPC". Now I am stumbling over some problems:

1.) I check for keyboard input with the READKEY function. How can I avoid that the key STRG-C stops the program? I want to use this key for the Copy-to-clipboard function. In the manual "CHECKBREAK" is mentioned but there it also says that it's not used (and setting it to FALSE doesn't change anything).

2.) Is there a (Free-Pascal) standard function to execute other programs synchronously AND asynchronously (so that there is no need to change this code for different platforms)? Or do I have to use WinAPI functions like CREATEPROCESS for that? Virtual-Pascal had an EXECFLAGS variable which controlled the behaviour of the EXEC function. Does something similar exist in Free-Pascal?

Thanks in advance for any help.

Jürgen Hestermann.

Marco van de Voort
to Jürgen Hestermann

In our previous episode, J�rgen Hestermann said:

Show quoted text 10 lines
I am trying to port some console programs to Free-Pascal(they use the CRT unit and originaly where written for Turbo-Pascal then they were ported to Virtual-Pascal). I use "MODE OBJFPC". Now I am stumbling over some problems: 1.) I check for keyboard input with the READKEY function. How can I avoid that the key STRG-C stops the program? I want to use this key for the Copy-to-clipboard function. In the manual "CHECKBREAK" is mentioned but there it also says that it's not used (and setting it to FALSE doesn't change anything).

Don't know if there is a generic function to do this. However in such cases it is easiest to look how FPC's biggest console app (the textmode IDE) does it.

2.) Is there a (Free-Pascal) standard function to execute other programs synchronously AND asynchronously (so that there is no need to change this code for different platforms)?

Synchronously: TProcess or ExecuteProcess
Asynchronously: TProcess

Or do I have to use WinAPI functions like CREATEPROCESS for that? Virtual-Pascal had an EXECFLAGS variable which controlled the behaviour of the EXEC function. Does something similar exist in Free-Pascal?

Do not use the dos.exec function. It has argument and path length problems (due to shortstrings), use the executeprocess function(s) instead. They are in sysutils.

And in general, have a look at tprocess:

http://www.freepascal.org/docs-html/fcl/process/index.html http://www.freepascal.org/docs-html/fcl/process/tprocess.html

and the fcl-process examples (hopefully) installed with your release.

Jürgen Hestermann
to Marco van de Voort
Marco van de Voort schrieb: However in such cases it is easiest to look how FPC's biggest console app (the textmode IDE) does it.

Thanks Marco for the quick answer. I tried to find where the IDE does the keyboard input but without success. Where in these 97 files could it be? It seems that it doesn't use CRT/READKEY anyway. So is it a problem of the CRT unit?

Do not use the dos.exec function. It has argument and path length problems (due to shortstrings), use the executeprocess function(s) instead. They are in sysutils.

Maybe someone can add this hint to the manual in the description of the EXEC function when it is changed anyway some day. I always wondered whether the DOS unit can still be used or whether it's just there for compatibility reasons.

Jürgen Hestermann.

Tomas Hajny
to Jürgen Hestermann
Jürgen Hestermann wrote 10 lines
> Marco van de Voort schrieb: > However in such cases > it is easiest to look how FPC's biggest console app (the textmode IDE) > does > it. Thanks Marco for the quick answer. I tried to find where the IDE does the keyboard input but without success. Where in these 97 files could it be? It seems that it doesn't use CRT/READKEY anyway. So is it a problem of the CRT unit?

IDE / FV is based on unit Keyboard, unit Crt is not (yet). General infrastructure for support of this functionality exists in the common parts of the FPC RTL, but it has not been added to all platforms yet (in particular, the support is currently available for OS/2 and for GO32v2 targets; for those it works for both unit Crt and unit Keyboard, IIRC). This functionality cannot be solved in completely platform independent way, because the underlying operating system maps this combination to a signal / exception and this needs to be addressed in platform specific manner.

Show quoted text 10 lines
> Do not use the dos.exec function. It has argument and path length > problems > (due to shortstrings), use the executeprocess function(s) instead. They > are > in sysutils. Maybe someone can add this hint to the manual in the description of the EXEC function when it is changed anyway some day. I always wondered whether the DOS unit can still be used or whether it's just there for compatibility reasons.

It is there mostly for compatibility. Nevertheless, in the case of the OS/2 target this includes compatibility with VP/2, so the OS/2 version of unit Dos provides ExecFlags as known in Virtual Pascal.

Tomas