[Lazarus] TProcess

Antonio Fortuny a.fortuny at sitasoftware.lu
Thu Sep 13 11:11:00 CEST 2012

> Hi list.
> Which function to use in Linux (if any) to get the process ID of a
> running process which is not mine. GetProcessID retrieves my own process
> ID.
> I'm using OpenProcess in Win
> Antonio.

This time it is not a question but a solution to a problem which was 
quite boring.

Using the TProcess component to launch antother task, I ran in trouble 
when dealing with piped commands like 'ps -s | grep something'
Got the solution:

   with TProcess.Create(nil) do try
     CommandLine := CmdLine.Text;
     Options := Options + [poWaitOnExit, poUsePipes, poStderrToOutPut];

CmdLine.Text := '/bin/sh -c ''ps -s | grep something'' '
THis works fine whatever the sh could be (I use bash)


More information about the Lazarus mailing list