On Tue, Jan 27, 2026 at 9:44 AM Aruna Hewapathirane via fpc-devel
<[email protected]> wrote:


> The attached screenshot shows the issue I’m running into with the displayed 
> output. I’m clearly missing something fundamental here, and I’d appreciate 
> any pointers in the right direction.

What happens if you output the Result to a file?

I use similar code (allbeit in a Lazarus program), I use
LoadFromStream(Proc.Output) instead of your CopyFrom(), not sure if
that matters.
===
type
  TBlockDeviceInfoStrings = type TStringList;
...
procedure GetBlockDeviceInfoStrings(BlockDeviceInfoStrings:
TBlockDeviceInfoStrings);
var
  Proc: TProcess;
  i: Integer;
begin
  BlockDeviceInfoStrings.Clear;
  Proc := TProcess.Create(nil);
  try
  Proc.Executable := 'lsblk';   //ToDo: get this from path  ??
  Proc.Parameters.Add('--pair'); //output in Key-Value pairs
  //Proc.Parameters.Add('-e7'); //exclude RAM drives
  Proc.Parameters.Add('-a');    //list all blockdevices
  Proc.Parameters.Add('-b');    //size in bytes
  Proc.Parameters.Add('-o');    //output
  
Proc.Parameters.Add('NAME,MOUNTPOINT,LABEL,FSTYPE,TYPE,PARTTYPE,UUID,MODEL,TRAN,RM,SIZE,FSSIZE,FSUSED,FSUSE%,FSAVAIL');
 //output columns
  Proc.Options := Proc.Options + [poWaitOnExit, poUsePipes];
  Proc.Execute;
  //writeln('lsblk: Proc.ExitCode=',Proc.ExitCode,',
Proc.ExitStatus=',Proc.ExitStatus);
  if not (Proc.ExitCode = 0) and (Proc.ExitStatus = 0) then
  begin
    writeln(stderr,'lsblk: ExitCode=',Proc.ExitCode,',
ExitStatus=',Proc.ExitStatus);
    Exit;
  end;
  BlockDeviceInfoStrings.LoadFromStream(Proc.Output);
  for i := BlockDeviceInfoStrings.Count - 1 downto 0 do
    if (Trim(BlockDeviceInfoStrings[i])='') then
      BlockDeviceInfoStrings.Delete(i);
  finally
    Proc.Free;
  end;
end;
===



-- 
Bart
_______________________________________________
fpc-devel maillist  -  [email protected]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to