Btw, the easiest is to just run the script interpreter with -c:
Note that this script is sensitive to what shell is used, which flabbergasted me for a short while. (/bin/sh didn't work) That's why I wasn't first post
{$mode delphi}
uses process;
var sin,sout : string;
begin
sin:='cat <(grep ''cpu '' /proc/stat) <(sleep 1 && grep ''cpu '' /proc/stat) | awk -v RS="" ''{print ($13-$2+$15-$4)*100/($13-$2+$15-$4+$16-$5)}''';
runcommand('/bin/bash',['-c',sin],sout);
// writeln(sin); // only used to check quoting of input
writeln(sout);
end.
Note that all ' are doubled in the input string. This is normal way in Pascal literals to make a ', kind of like \ escape in C.
At the end there is a doubled ' + another ' from closing the pascal literal.
The example is basically the same as Jurassic Pork's, just using some predefined helper routines, and using direct commandline scripts (-c) instead of writing it out to file.
If you just want to run, and not get the output, you can also use fpsystem()