Трубопровод между двумя программами Delphi

Я хочу сделать программу, которая будет делать трубопровод между двумя программами

Получая ввод от первого, передавая его второму, который будет обрабатывать его и возвращать мне, который я передам первым

  if Input <> '-' then
    InS := TFileStream.Create(Input, fmOpenRead or fmShareDenyWrite)
  else
    InS := THandleStream.Create(GetStdHandle(STD_INPUT_HANDLE));

  if Output <> '-' then
    OutS := TFileStream.Create(Output, fmCreate or fmShareExclusive)
  else
    OutS := THandleStream.Create(GetStdHandle(STD_OUTPUT_HANDLE));

  FillChar(StartupInfo, sizeof(StartupInfo), 0);
  FillChar(ProcessInfo, sizeof(ProcessInfo), 0);

  SecurityAttributes.nLength := sizeof(SecurityAttributes);
  SecurityAttributes.bInheritHandle := True;
  SecurityAttributes.lpSecurityDescriptor := Nil;

  CreatePipe(OutPipe, InPipe, @SecurityAttributes, 0);

  StartupInfo.cb := sizeof(StartupInfo);
  StartupInfo.wShowWindow := SW_HIDE;
  StartupInfo.dwFlags := STARTF_USESTDHANDLES or STARTF_USESHOWWINDOW;
  StartupInfo.hStdInput := InPipe;
  StartupInfo.hStdOutput := OutPipe;

  Handle := CreateProcess(PChar(CLSAppInfo.CLSExeName),
    PChar(Format('a - -', [])), nil, nil, True, 0, nil, PChar(GetCurrentDir),
    StartupInfo, ProcessInfo);

  if Handle then
  begin
    GetMem(Buffer, BLOCK_SIZE);
    repeat
      ReadByte := InS.Read(Buffer^, BLOCK_SIZE);
      isOK := WriteFile(InPipe, Buffer^, ReadByte, WroteByte, nil);

      WriteLn(ReadByte.ToString);
      WriteLn(isOK.ToString());

      if (not isOK) or (ReadByte = 0) then
        break;

      repeat
        isOK := ReadFile(OutPipe, Buffer^, 255, ReadByte, nil);
        if not isOK then
          break;
        if ReadByte = 0 then
          break;

        OutS.Write(Buffer, ReadByte);
      until 0 = 1;
    until 0 = 1;

    FreeMem(Buffer);
    CloseHandle(ProcessInfo.hThread);
    CloseHandle(ProcessInfo.hProcess);
  end;

  CloseHandle(InPipe);
  CloseHandle(OutPipe);

  OutS.Free;
  InS.Free;

Но это только запускает программы, а программы заканчиваются, ничего не делая

0 ответов

Другие вопросы по тегам