[fpc-pascal] Executing another program from Pascal

Hans Mårtensson hm at os.dk
Tue Mar 28 21:40:45 CEST 2006


In good old days the Turbo Pascal had an EXEC procedure that could 
execute another program by invoking the DOS command interpreter.

In better new days the FPC does not seem to have such an option, or I 
couldn’t find it in the docs.
Now I am particularly interested in doing such a thing in a Linux system.

I have found in the unix unit a function FPEXECV(path, pp) that may be 
used for it, but it leaves a few questions to me.

According to the docs the function does not return (if it succeeds). Is 
there no way of calling another program and then continue the calling 
program? Could it be done by starting a new thread, putting the call 
into that thread and let that thread not return while the main program 
continues? Will it leave allocated memory, that is never freed?

If the function does not return, why is there a return integer value 
defined?
(Or: why is it called a function, when it does not return?)

In the doc’s example the FPEXECV(path, pp) has the same pchar in the 
path and as the first pchar of the pchar array that pp points to. I have 
tried similar examples, and they always seem to work with the same phar 
in the two places, but not otherwise. Is there some deeper philosophy in 
having the program-name in both path and in the first phar of the array?

Hans Maartensson




More information about the fpc-pascal mailing list