как получить вывод другой программы ?
можно запустить  с перевыводом в файл, и его отпарсить, но должно быть что-то проще =)
			
				Модератор: Модераторы

Process1.Create(nil);
Process1.CommandLine:='qqq.exe';
Process1.Options := Process1.Options + [poWaitOnExit, poUsePipes];
Process1.Execute;
Memo1.Lines.LoadFromStream(Process1.Output);
Process1.Free; 
Attid писал(а):или второй вопрос, как получить вывод другой программы ?
ev писал(а):Memo1.Lines.LoadFromStream(Process1.Output);
{$MODE OBJFPC}{$H+}
uses windows, pipes, process;
function ReadStr(Stream: TInputPipeStream): AnsiString;
begin
  SetLength(Result, Stream.NumBytesAvailable);
  Stream.Read(Result[1], Length(Result));
end;
var
  p: TProcess;
  s: ansistring;
  h: array [0..1] of THandle;
begin
  p := TProcess.Create(nil);
  Assert(p <> nil);
  p.Options := [poUsePipes];
  p.CommandLine := 'svn status --verbose ' + ParamStr(1);
  p.Execute;
  h[0] := p.ProcessHandle;
  h[1] := p.Output.Handle;
  S := '';
  while p.Running do
  begin
    WaitForMultipleObjects(2, @h, false, INFINITE);
    s := s + ReadStr(p.Output);
  end; // while
  writeln('Len: ', Length(S));
  writeln('"', S, '"');
end.#include <stdio.h>
#include <unistd.h>
int main (void)
{
        int pds[2];
        char ch;
        if (!fork()) {
                pipe (pds);
                dup2 (1, pds[1]);
                sleep (2);
                execlp ("ls", "ls", "/", NULL);
        }
        while (read (pds[0], &ch, 1) > 0)
                write (1, &ch, 1);
        wait (NULL);
        return 0;
}
Я что-то подобное пробовал - под Windows не работает.

uses  process;
****
  with TProcess.Create(nil) do
  try
    CommandLine:=Edit1.Text;
    Options := Options + [poWaitOnExit, poUsePipes];
    Execute;
    Memo1.Lines.LoadFromStream(Output);
  finally
    Free;
  end;
uses baseunix;
*****
var
  pid :longint;
  pds :TFilDes;
  ch : Char;
begin
  pid:=fpFork;
  if pid=0 then
   begin
      if FpPipe(pds) = -1 then
      begin
        ShowMessage('error calling pipe');
        halt(1);
      end;
      FpDup2(1, pds[1]);
      FpSleep (2);
      FpExecv('/bin/ls',nil);
      ShowMessage('Error exec');
   end
  else
   if pid=-1 then
    begin
      ShowMessage('Error fork');
    end;
  while fpread(pds[0], ch, sizeof(ch)) > 0 do
    Memo1.Lines.Text := Memo1.Lines.Text + ch;
  FpWait(pid);    
end;



uses  process;
****
  with TProcess.Create(nil) do
  try
    CommandLine:=Edit1.Text;
    Options := Options + [poWaitOnExit, poUsePipes];
    Execute;
    Memo1.Lines.LoadFromStream(Output);
  finally
    Free;
  end; 
 




Stream.NumBytesAvailable;    fpExecv('/opt/firebird/bin/isql', StringToPPChar(pchar('-help'),1));$ /opt/firebird/bin/isql -help | grep SQL
Attid писал(а):счастья нет =(
в венде из-за отсутствия Stream.NumBytesAvailable; ничего не работает, но я там даже не смотрел не так критично.
Attid писал(а):а вот под линухом
fpExecv('/opt/firebird/bin/isql', StringToPPChar(pchar('-help'),1));
хоть убей не возрощает ничего через pipe =(
есть еще мысли ?
/opt/firebird/bin/isql -help > x.txtAttid писал(а):так что в пример по лину просто добавь пример параметра и пишем его рабочим


Вернуться в Free Pascal Compiler
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 1