MichaSchumann
MichaSchumann

Reputation: 1493

Run linux command line utility from delphi app and capture output

How can I run a command line utility in Linux from a Delphi 10.2/10.3 application and capture the output for further processing?

I need the capturing to go line by line to watch the progress as I am going to use a GUI application with FMXLinux. This approach for OSX works perfectly

Delphi: Capture OSX console output

Thanks!

Upvotes: 0

Views: 960

Answers (1)

MichaSchumann
MichaSchumann

Reputation: 1493

The example mentioned above created for OSX works perfectly on Linux64 (tested with current Ubuntu) with a small modification in the definitions. As the changes are small, I don't repeat the code (see Delphi: Capture OSX console output):

  1. Add

    Posix.Base

    and

    Posix.Fcntl

    to uses clause

  2. Remove line with path to libc.dylib
  3. Change libc function declarations by exchanging the underscore by _PU:

    ... cdecl; external libc name _PU + 'popen'; ...

Now it compiles and works for OSX and Linux as well!

Upvotes: 2

Related Questions