[fpc-devel] [Lazarus] Changes to TProcess
zeljko
zeljko at holobit.hr
Wed Jan 3 14:57:24 CET 2024
On 03. 01. 2024. 14:28, Michael Van Canneyt via lazarus wrote:
>
> Hello,
>
> I merged a significant evolution of the TProcess component to FPC trunk.
>
> Until recently, there were 2 options for TProcess when starting a new
> process:
>
> - use the parent process standard input/output/error
> - use pipes to make the standard input/output/error available as streams
> in the parent process.
>
> This has been enhanced with the following new possibilities:
>
> - For the new process, the standard input/output/error can be configured
> separately.
>
> - You can specify a filename as input/output/error.
> (additionally, you can rewrite or append to the file in case of output)
>
> - You can specify a custom I/O handle as input/output/error
> (e;g. at least on unix, you can pass a socket handle)
>
> - You can specify the null file (/dev/null on unixes or NULL on windows)
>
> - You can specify another TProcess instance.
>
> The last option means that you can now chain processes, just as the
> command shell does.
>
> So the equivalent of the following chain of commands:
>
> command <input.txt | sed s/delphi/FPC/g > file.txt
>
> would then be
>
> Proc.Executable:='command';
> Proc.InputDescriptor.FileName:='input.txt';
> Proc2.Executable:='sed';
> Proc2.Parameters.Add('s/delphi/FPC/g');
> Proc2.OutputDescriptor.FileName:='file.txt';
> Proc.OutputDescriptor.Process:=Proc2;
> Proc2.Execute;
> Proc.execute;
>
> Needless to say, the component remains backwards compatible.
>
> There is now a testsuite for the TProcess command, so everything was
> tested.
> but nothing beats testing in the wild, so I would appreciate it if people
> could test it and provide feedback.
Great feature :)
Thanks Michael
zeljko
More information about the fpc-devel
mailing list