Hey guys. Many users do not know about the class TProcess. That class allows you to launch an external application in Lazarus. And, it also exported to Lape. Today I'll show you how to use it. How does this help you? You are only limited by your imagination.
So, my test form looks:
w5qyEyTb.png
And then we use the functional of TProcess to execute an external program and get it output:
Simba Code:
procedure RunCommand(Cmd: string; Lines: TStrings);
var
AProcess: TProcess;
Buf: array [1..BUFSIZE] of char;
I, Count: longint;
ss: string;
begin
Lines.Clear;
AProcess.Init(nil);
try
AProcess.SetCommandline(Cmd);
AProcess.setOptions([poUsePipes, poNoConsole]);
AProcess.execute;
repeat
count := AProcess.GetOutput().Read(buf, BufSize);
for I := 1 to count do
ss := ss + buf[i];
until Count = 0;
Lines.Add(ss);
finally
AProcess.Free;
end;
end;
After call of this function with params like 'netstat -an' we get the result:
w5qyEyTa.png
Well, after that, as I said - you can only limit is your imagination. I showed you the mechanism by which it is possible to significantly increase the scope of the Simba using.
My test script can be found in attachment.
Thank you for attention!
Cheers,
Cynic.
PS:
Reference of TProcess methods:
http://www.freepascal.org/docs-html/.../tprocess.html
FPC wiki of TProcess:
http://wiki.freepascal.org/Executing...grams#TProcess