两个方法

function RunDosCommand(Command: string): string;
var
hReadPipe: THandle;
hWritePipe: THandle;
SI: TStartUpInfo;
PI: TProcessInformation;
SA: TSecurityAttributes;
BytesRead: DWORD;
Dest: array[..] of AnsiChar;
CmdLine: array[..] of char;
TmpList: TStringList;
Avail, ExitCode, wrResult: DWORD;
osVer: TOSVERSIONINFO;
tmpstr: AnsiString;
begin
osVer.dwOSVersionInfoSize := Sizeof(TOSVERSIONINFO);
GetVersionEX(osVer); if osVer.dwPlatformId = VER_PLATFORM_WIN32_NT then
begin
SA.nLength := SizeOf(SA);
SA.lpSecurityDescriptor := nil; //@SD;
SA.bInheritHandle := True;
CreatePipe(hReadPipe, hWritePipe, @SA, );
end
else
CreatePipe(hReadPipe, hWritePipe, nil, );
try
FillChar(SI, SizeOf(SI), );
SI.cb := SizeOf(TStartUpInfo);
SI.wShowWindow := SW_HIDE;
SI.dwFlags := STARTF_USESHOWWINDOW;
SI.dwFlags := SI.dwFlags or STARTF_USESTDHANDLES;
SI.hStdOutput := hWritePipe;
SI.hStdError := hWritePipe;
StrPCopy(CmdLine, Command);
if CreateProcess(nil, CmdLine, nil, nil, True, NORMAL_PRIORITY_CLASS, nil, nil, SI, PI) then
begin
ExitCode := ;
while ExitCode = do
begin
wrResult := WaitForSingleObject(PI.hProcess, );
if PeekNamedPipe(hReadPipe, @Dest[], , @Avail, nil, nil) then
begin
if Avail > then
begin
TmpList := TStringList.Create;
try
FillChar(Dest, SizeOf(Dest), );
ReadFile(hReadPipe, Dest[], Avail, BytesRead, nil);
TmpStr := Copy(Dest, , BytesRead - );
TmpList.Text := TmpStr;
Result := string(tmpstr);
finally
TmpList.Free;
end;
end;
end;
if wrResult <> WAIT_TIMEOUT then ExitCode := ;
end;
GetExitCodeProcess(PI.hProcess, ExitCode);
CloseHandle(PI.hProcess);
CloseHandle(PI.hThread);
end;
finally
CloseHandle(hReadPipe);
CloseHandle(hWritePipe);
end;
end; function GetURLResult(url: string): string;
begin
Result := RunDosCommand(Format('http.exe "%s"', [url]));
if Result.ToLower.StartsWith('error') then
Exit('error'); Result := Copy(Result, , Result.IndexOf('}') + );
end;

调用方式:

Edit1.Text := GetURLResult('http://0.0.0.0/test/getResult/94bdb076dcdb8f6bab77321ece18f8af');

最新文章

  1. Docker初体验
  2. 洛谷P1156 垃圾陷阱
  3. cocos2d-x UserDefault
  4. 关于Handler与异步消息处理循环的摘抄
  5. 域控制器安全策略在哪里 Windows server 2008
  6. JQ图片文件上传之前预览功能
  7. HandlerThread原理分析
  8. Tarjan算法(缩点)
  9. Go语言流程控制
  10. vue中computed和watch
  11. 使用 cacti 监控 windows 服务器硬盘的 I/O 状况
  12. tomcat 最大并发数
  13. QQ去除未读状态的动画
  14. ASP.NET中使用JavaScript实现图片自动水平滚动效果
  15. Scrum立会报告+燃尽图(十月二十七日总第十八次)
  16. linux自动获得mac地址,修改网络配置
  17. MIS货物拆包销售的问题
  18. 关于绑定的C#代码+转换器
  19. opencv:直方图操作
  20. 使用ASP.NET Core实现Docker的HealthCheck指令

热门文章

  1. day4-2数组及方法
  2. day4-1深入理解对象之创建对象
  3. ab的压力测试(转)
  4. Servlet 设置字符编码filter
  5. 使用eclipse创建一个简单的Java Web应用程序
  6. linux命令系列-mv(移动-重命名)
  7. 如何查看python的notebook文件.ipynb
  8. 在java中调用python方法
  9. Scrapy 中的模拟登陆
  10. MySQL实现主从复制功能