Sign in Join

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

Mailing lists / fpc-devel / 2024-01

Changes to TProcess

5 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

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

Michael Van Canneyt

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.

Enjoy,

Michael.

Reply by email

zeljko
to Michael Van Canneyt
Michael Van Canneyt wrote 51 lines
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

Reply by email

Michalis Kamburelis
to Michael Van Canneyt: I merged a significant evolution of the TProcess component to FPC trunk. Until recently,…
Michael Van Canneyt wrote 5 lines
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 additions -- making it easier to use pipes is important, and it's very natural to be able to connect with pipes a few TProcess instances.

I tested the changes with Castle Game Engine (not using new features yet, just tested it is backwards-compatible for us), it works great. We use TProcess in our build tool and editor (editor runs build tool, build tool can run FPC and other programs).

Regards,
Michalis

Reply by email

Michael Van Canneyt
to Michalis Kamburelis
Michalis Kamburelis wrote 15 lines
Michael Van Canneyt wrote: > 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 additions -- making it easier to use pipes is important, and it's very natural to be able to connect with pipes a few TProcess instances. I tested the changes with Castle Game Engine (not using new features yet, just tested it is backwards-compatible for us), it works great. We use TProcess in our build tool and editor (editor runs build tool, build tool can run FPC and other programs).

Thanks for the feedback.

There were some fixes yesterday, but relevant only for "ancient" platforms that do not have proper pipe support, I guess that is not your case.

The FPC buildchain also uses TProcess, so we'd notice serious shortcomings quite quickly :-)

Michael.

Reply by email