调用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 ...
随机推荐
- c++构造函数的初始化列表(翁恺c++公开课[13])
初始化列表形式: class Point { private: const float x,y; Point(float xa = 0.0, flato ya = 0.0):y(ya),x(xa) { ...
- 整理了一下NLP中文数据集
个人理解: 句子相似性判断.情感分析.实体识别.智能问答,本质基本上都是分类任务. 阅读理解(抽取式.回答式.完形填空)是逐个候选项的分类问题处理. 参考 https://github.com/chi ...
- 微信小程序引用外部js,引用外部样式,引用公共页面模板
https://blog.csdn.net/smartsmile2012/article/details/83414642 ================小程序引用外部js============= ...
- UISearchBar设置背景色
1.关于UISearchBar的背景颜色,竟然要如下设置才正常: [documentSearchView setBackgroundImage:[UIImage new]]; documentSear ...
- Scrapy 下载文件和图片
我们学习了从网页中爬取信息的方法,这只是爬虫最典型的一种应用,除此之外,下载文件也是实际应用中很常见的一种需求,例如使用爬虫爬取网站中的图片.视频.WORD文档.PDF文件.压缩包等. 1.Files ...
- MyBatis插入时获取自增长主键
在某些场景下,我们需要使用mybatis返回生成的主键值.Mybatis在insert和update标签中就提供了这种功能. 方法1: <insert id=”indetifyId” useGe ...
- vue v-model 数据双向绑定(笔记)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- centos 访问win共享
yum install samba 安装samba (其实我们只用到samba里面的winbind以便我们能够用windows机器的名称找到该机器的网络地址,在下面叙述的过程会用到.而且也要确定在 w ...
- QQ企业通知识点---ClassSerializers
Serializers 串列器 序列化器 串行器 MemoryStream 创建其支持存储区为内存的流. BinaryFormatter 以二进制格式将对象或整个连接对象图形序列化和反序列化 ...
- 模板+解题报告:luogu P3385 【模板】负环
题目链接:P3385 [模板]负环 缩点板子. 看日报上说\(DFS\)会炸(我确实打炸了),就根据他的说明\(yy\)了\(BFS\),多一个记录步数的数组即可(我用的\(len[]\)),若\(l ...