Calling Linux Commands from Delphi

4 Responses

  1. The simplest solution for UTF8 is to completely replace the BufferToString() function with the Delphi system function Utf8ToString()….

    while fgets(@data[0],Sizeof(Data),Handle)<>nil do begin
    Write(Utf8ToString(@Data[0]));
    end;

    However, Utf8ToString() does not have a character limiter to stop it from overrunning the end of the buffer. In order to resolve this you would need to pass a pre-zero’d buffer into fGets() and pass the size of the buffer less one byte (to protect the terminating zero). Or otherwise, simply pass a buffer large enough for the content + zero byte.

  2. andrew.sovtsov@embarcadero.com says:

    Hi Craig,
    Nice post and very useful one!
    In practice your BufferToString function works incorrectly with non-ascii symbols (e.g. UTF8)

  1. 2017-05-18

    […] In this post, as in the webinar, I’m referencing code from my earlier blog post on launching external applications under linux: http://chapmanworld.com/2017/04/06/calling-linux-commands-from-delphi/ […]

  2. 2018-06-22

    […] Calling Linux Commands from Delphi […]

Leave a Reply