Calling Linux Commands from Delphi

6 Responses

  1. tom liu says:

    Hi,Anderson Dapper Rocha

    when I use your code in console, It’s ok.
    when I use your code in gui enviroument, the program has no response, no focus.
    what should i do ?
    Thank’s a lot.

    • Apologies that it’s been a while since you posted this question.
      I’m not sure how you’re running the code in GUI because Delphi for Linux does not support GUI applications, which may be the problem in it’s self.
      If you’re using some Delphi GUI for Linux framework, such as CrossVCL or other, you may need to remove the Write/Writeln calls from the code.

  2. 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.

  3. 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