调用dos
两个方法
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的更多相关文章
- C#如何调用DOS命令
在使用C#编辑过程中,通常需要利用外部命令来执行一些操作,从而完成特定的功能.下面小编就以利用C#调用DOS命令"Ver"显示系统版本号为例,给初学C#语言的网友讲解一下具体的调用 ...
- matlab 调用dos命令和文件操作
第一.利用!直接调用,简单方便,可以带操作对象:!del A.bat 第二.调用system函数或者dos函数,既可以实现功能,又返回参数,能检查执行情况,方便后面程序的开发,推荐这个 [status ...
- VBA调用DOS程序两种方法
Set wsh = VBA.CreateObject("WScript.Shell") 'wsh.Run strExePath & " g", vbHi ...
- ASP.NET调用dos命令获取交换机流量
protected void btn_Cisco_Click(object sender, EventArgs e) { try { string ip = txt_ip.Value; string ...
- 如何在C语言 C++里面调用 DOS命令
C里面调用可以用[system("命令")]这样的形式. 但需要include <stdlib.h> 例子如下: #include <stdio.h> #i ...
- 【C#】调用DOS命令
public interface IRunConsole { void Run(); } public abstract class RunConsole:IRunConsole { public a ...
- c++ CreateProcess调用dos命令
// test.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <windows.h> #include &l ...
- c++调用DOS命令,不显示黑屏
WinExec("Cmd.exe /C md c://12", SW_HIDE); 注释:/c是什么意思,不用/C会报错 CMD [/A | /U] [/Q] [/D] [/E:O ...
- C# 调用DOS 命令
class NetWorkDeviceInfo { public static string GetDeviceInfo() { System.Diagnostics.Process p = new ...
随机推荐
- idea设置自带的maven为国内镜像
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/panchang199266/articl ...
- 记一次安装体验:pwn工具
几天前删了JDK,结果和VM在一个目录中,结果VM全没了,重安走起 记载一下安装虚拟机出现的问题,官网一个字....慢,于是找了百度网盘,据说win10版本太低没法用,我就下了vw15.5.0(建立在 ...
- Linux内核5.4正式将华为EROFS超级文件系统合入主线
导读 近期,Linux内核5.4系列宣布全面可用,添加了许多新功能,更强的安全性和更新的驱动程序,以提供更好的硬件支持.Linux内核5.4增加对微软exFAT文件系统的支持,另外还支持内核锁定功能, ...
- 异常 日志-<多重catch语句>
try{ }catch(){ }catch(){ }
- Android studio For Mac 安装
简介: Google在2013的I/O开发者大会上正式对外宣布Android Studio将作为Android开发的主要IDE,它是基于IntelliJ IDEA打造的一款专门开发Android的神器 ...
- java 中类加载器
jar 运行过程和类加载机制有关,而类加载机制又和我们自定义的类加载器有关,现在我们先来了解一下双亲委派模式. java 中类加载器分为三个: BootstrapClassLoader 负责加载 ${ ...
- uniGUI之换肤(17)
在MainModule里 Design 模式 1]RecallLastTheme 设为True 2]Theme选一个皮肤 总共有 classicgraycrispneptunetritontrito ...
- 使用C语言实现文件的操作
#include <stdio.h> int main(int argc, char* argv[]) { // 创建文件类型 FILE* file; char buf[1024] = { ...
- Linux系统需要关闭的安全防护
1.关闭网络管理 我们一般在开发时都会将它关闭掉,因为它在做集群的时候,可能会劫持 systemctl status NetworkManager systemctl stop NetworkMana ...
- 吴裕雄--天生自然HADOOP操作实验学习笔记:协同过滤算法
实验目的 初步认识推荐系统 学会用mapreduce实现复杂的算法 学会系统过滤算法的基本步骤 实验原理 前面我们说过了qq的好友推荐,其实推荐算法是所有机器学习算法中最重要.最基础.最复杂的算法,一 ...