[fpc-pascal] Getting an output string from a TProcess

luciano de souza luchyanus at gmail.com
Fri Jun 1 16:23:42 CEST 2012


Hello all,

I want to execute FPC, but filtering the output in order to show only
the necessary information. The reason is I am blind, I use screen
reader and, in the console environment, it's not possible to read the
rows below without firstly read the rows above.
My intention is to use TProcess, calling fpc commmandline, replacing
all the non necessary information by ''. My first line will by
something like "compiling ' or 'linking '.
For this purpose, TProcess is wonderful.
I want a function that receives a commandline string and returns an
output string. This return will be afterwards used to  replacements.

function execute(AProcess: TProcess; instr: string):string;
var
buffer: integer;
begin
with AProcess do
begin
commandline := instr;
options := [poUsePipes];
execute;
output.read(buffer, 10);
result := buffer;
end;
end;

I am confused due to some reasons:
1. Commandline is signed as deprecated, so what is the best way to
pass a string to TProcess? Is the  commandline the first item of the
tstrings called parameter?
2. The output is a class derived from THandleStream. As the read
method is override, its behaviour is different from TStream.
So I ask: what's the correct code to inform as argument a TProcess and
a instruction string and as a return, to get the output string?

Regards,
Luciano



More information about the fpc-pascal mailing list