Never have played with FileMapping.
The output from the externally executed program is pipped into a MemoryStream as below, but how to put the input data into a MemoryStream and get it into the external program, I don't know.
function TForm1.RunExternalApp(DosApp:String) : string;
const READ_BYTES = 2048;
var aProcess: TProcess;
MemStream: TMemoryStream;
NumBytes: LongInt;
BytesRead: LongInt;
Lines: TStringList;
begin
MemStream := TMemoryStream.Create;
Lines := TStringList.Create;
BytesRead := 0;
aProcess := TProcess.Create(nil);
aProcess.CommandLine := DosApp;
aProcess.ShowWindow := swoHIDE;
aProcess.Options := aProcess.Options + [poUsePipes];
aProcess.Execute;
while aProcess.Running do begin
MemStream.SetSize(BytesRead + READ_BYTES);
NumBytes := aProcess.Output.Read((MemStream.Memory + BytesRead)^, READ_BYTES);
if NumBytes > 0 then
Inc(BytesRead, NumBytes)
else
BREAK;
end;
MemStream.SetSize(BytesRead);
Lines.LoadFromStream(MemStream);
Result := Lines.Text;
aProcess.Free;
Lines.Free;
MemStream.Free;
end;