Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > Delphi программирование > Общие вопросы Delphi
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 29.03.2021, 14:36   #1
Another777
 
Регистрация: 29.11.2020
Сообщений: 5
По умолчанию Выполнение php скрипта в delphi

Доброго времени суток!

Скачал архив с php интерпертатором, с официального сайта.

Передаю через командную строку имя php скрипта через delphi,
для выполнения, скрипт выполняется. Передаю get параметры, все ок.

Не могу понять, как отправлять и получать post параметры. Помогите пожалуйста.

Исходник:
Код:
var
  s: string;
begin
  s := Path('php\php.exe ');
  s := s + Path('index.php');

  TextToWebBrowser(WebBrowser1, GetDosOutput(s));
end.

function Path(s: string): string;
begin
  Result := PathAppend(ExtractFilePath(paramstr(0)), s);
end; //Path

function PathAppend(path, str: string): string;
begin
  if path[Length(path)] <> '\' then path := path + '\';
  result := path + str;
end; //PathAppend  

procedure TextToWebBrowser(WB: TWebBrowser; Text: string);
var             
  V: OleVariant;
  Document: IHTMLDocument2;
begin
   if WB.Document = nil then WB.Navigate('about:blank');
   while WB.Document = nil do Application.ProcessMessages;
   Document := WB.Document as IHtmlDocument2;
   V := VarArrayCreate([0, 0], varVariant);
   V[0] := Text;
   Document.Write(PSafeArray(TVarData(v).VArray));
   Document.Close;
end; //TextToWebBrowser

function GetDosOutput(DosApp: String): string;
const
  ReadBuffer = 2400;
var
  Buffer: PChar;
  BytesRead: DWord;
  Apprunning: DWord;     
  start: TStartUpInfo;    
  ReadPipe, WritePipe: THandle;  
  Security: TSecurityAttributes; 
  ProcessInfo: TProcessInformation;
begin
  result := '';
  
  with Security do
  begin
    nlength := SizeOf(TSecurityAttributes);
    binherithandle := true;
    lpsecuritydescriptor := nil;
  end;

  if Createpipe(ReadPipe, WritePipe, @Security, 0) then
  begin
    Buffer  := AllocMem(ReadBuffer + 1);
    FillChar(Start,Sizeof(Start),#0);
    start.cb          := SizeOf(start);
    start.hStdOutput  := WritePipe;
    start.hStdInput   := ReadPipe;
    start.dwFlags     := STARTF_USESTDHANDLES +
                         STARTF_USESHOWWINDOW;
    start.wShowWindow := SW_HIDE;

    if CreateProcess(nil,
          PChar(DosApp),
          @Security,
          @Security,
          true,
          NORMAL_PRIORITY_CLASS,
          nil,
          nil,
          start,
          ProcessInfo)
    then
    begin
      repeat
        Apprunning := WaitForSingleObject(ProcessInfo.hProcess, 100);
        Application.ProcessMessages;
      until (Apprunning <> WAIT_TIMEOUT);
      repeat
        BytesRead := 0;
        ReadFile(ReadPipe, Buffer[0], ReadBuffer, BytesRead, nil);
        Buffer[BytesRead]:= #0;
       //OemToAnsi(Buffer,Buffer);
        result := result + String(Buffer);
      until (BytesRead < ReadBuffer);
    end;
    CloseHandle(ProcessInfo.hProcess);
    CloseHandle(ProcessInfo.hThread);
    CloseHandle(ReadPipe);
    CloseHandle(WritePipe);   
    FreeMem(Buffer);
  end;
end;

Последний раз редактировалось Another777; 29.03.2021 в 14:38.
Another777 вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц

Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Не корректное выполнение скрипта [PHP] spectrum988 Помощь студентам 0 11.02.2016 23:49
Остановить выполнение скрипта max9123 Общие вопросы Delphi 2 02.11.2013 11:59
выполнение скрипта по крону Mortimoro PHP 3 03.09.2012 15:30
Выполнение PHP-скрипта по времени ardor PHP 6 11.03.2012 14:15
как из delphi задать выполнение php-скрипта на сайте? Dux Работа с сетью в Delphi 4 28.03.2011 12:44