两个方法

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');

调用dos的更多相关文章

  1. C#如何调用DOS命令

    在使用C#编辑过程中,通常需要利用外部命令来执行一些操作,从而完成特定的功能.下面小编就以利用C#调用DOS命令"Ver"显示系统版本号为例,给初学C#语言的网友讲解一下具体的调用 ...

  2. matlab 调用dos命令和文件操作

    第一.利用!直接调用,简单方便,可以带操作对象:!del A.bat 第二.调用system函数或者dos函数,既可以实现功能,又返回参数,能检查执行情况,方便后面程序的开发,推荐这个 [status ...

  3. VBA调用DOS程序两种方法

    Set wsh = VBA.CreateObject("WScript.Shell") 'wsh.Run strExePath & " g", vbHi ...

  4. ASP.NET调用dos命令获取交换机流量

    protected void btn_Cisco_Click(object sender, EventArgs e) { try { string ip = txt_ip.Value; string ...

  5. 如何在C语言 C++里面调用 DOS命令

    C里面调用可以用[system("命令")]这样的形式. 但需要include <stdlib.h> 例子如下: #include <stdio.h> #i ...

  6. 【C#】调用DOS命令

    public interface IRunConsole { void Run(); } public abstract class RunConsole:IRunConsole { public a ...

  7. c++ CreateProcess调用dos命令

    // test.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <windows.h> #include &l ...

  8. c++调用DOS命令,不显示黑屏

    WinExec("Cmd.exe /C md c://12", SW_HIDE); 注释:/c是什么意思,不用/C会报错 CMD [/A | /U] [/Q] [/D] [/E:O ...

  9. C# 调用DOS 命令

    class NetWorkDeviceInfo { public static string GetDeviceInfo() { System.Diagnostics.Process p = new  ...

随机推荐

  1. vs2010 c++中内嵌汇编代码

    在研究汇编时,需要自己写点汇编代码测试,用Ollydbg写每次加载程序就没了,不是很方便. 可以考虑直接在程序中写入汇编代码,只需要加上关键字“_asm”宏(C++代码中). 如下示例 编写环境 :v ...

  2. Gof 设计模式

    设计模式的用途(参考) 设计模式代表了最佳实践,通常被有经验的面向对象的软件开发人员采用.设计模式是软件开发人员在软件开发过程中面临一般问题的解决方案.这些解决方案是众多软件开发人员在相当长的时间的实 ...

  3. SpringBoot 获得 properties 文件中数据方式

    参考:https://blog.csdn.net/qq_37171353/article/details/78005845

  4. Go的WaitGroup

    goroutine使用方便,但是如果不加以处理一般会deadlock,因为goroutine配合Chanel的话只能是一进一出,否则就会卡在那里.下面一个示例就是利用这个WaitGroup处理这种死锁 ...

  5. cookie、 Session Storage 、 Local Storage

    问题描述: 使用Ajax, Controller 传回来 JSON 字符串(待处理的信息) 在 Ajax 中实现页面跳转 window.location.href="/jsp/index.j ...

  6. html常用整理

    视频链接:https://www.bilibili.com/video/av5862916?from=search&seid=12139895566389560177 我的第一个html &l ...

  7. PyCharm底部控制台console界面开启/取消自动换行

    File --> Settings --> Editor --> General --> Console中 勾选右侧第一项Use soft wraps in console(选 ...

  8. JS数组精简的十三个技巧

    1.删除数组的重复项 第一种方式 var fruits = ['banana', 'apple', 'orange', 'apple', 'orange', 'grape', 'watermelon' ...

  9. 子组件props接受父组件传递的值 能修改吗?

    vue2.0 子组件props接受父组件传递的值,能不能修改的问题整理 父组件代码: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ...

  10. activity添加切换动画之后出现的黑色背景问题

    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">     & ...