delphi 编写一个dos 窗体
+
//dos 仿真程序 delphi 窗体实现!
function GetDosOutput(CommandLine: string; Work: string = 'C:\'): string;
var
SA: TSecurityAttributes;
SI: TStartupInfo;
PI: TProcessInformation;
StdOutPipeRead, StdOutPipeWrite: THandle;
WasOK: Boolean;
Buffer: array[0..255] of AnsiChar;
BytesRead: Cardinal;
WorkDir: string;
Handle: Boolean;
begin
Result := '';
with SA do begin
nLength := SizeOf(SA);
bInheritHandle := True;
lpSecurityDescriptor := nil;
end;
CreatePipe(StdOutPipeRead, StdOutPipeWrite, @SA, 0);
try
with SI do
begin
FillChar(SI, SizeOf(SI), 0);
cb := SizeOf(SI);
dwFlags := STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES;
wShowWindow := SW_HIDE;
hStdInput := GetStdHandle(STD_INPUT_HANDLE); // don't redirect stdin
hStdOutput := StdOutPipeWrite;
hStdError := StdOutPipeWrite;
end;
WorkDir := Work;
Handle := CreateProcess(nil, PChar('cmd.exe /C ' + CommandLine),
nil, nil, True, 0, nil,
PChar(WorkDir), SI, PI);
CloseHandle(StdOutPipeWrite);
if Handle then
try
repeat
WasOK := ReadFile(StdOutPipeRead, Buffer, 255, BytesRead, nil);
if BytesRead > 0 then
begin
Buffer[BytesRead] := #0;
Result := Result + Buffer;
end;
until not WasOK or (BytesRead = 0);
WaitForSingleObject(PI.hProcess, INFINITE);
finally
CloseHandle(PI.hThread);
CloseHandle(PI.hProcess);
end;
finally
CloseHandle(StdOutPipeRead);
end;
end;
最新文章
- [LintCode] Find Peak Element 求数组的峰值
- 双守护进程(不死service)-5.0系统以下
- java并发编程(三)线程挂起,恢复和终止的正确方法
- C#通过SSH连接MySql
- FFMpeg的码率控制
- Android--SQLite的使用
- ORACLE 11G R2 修改";用户名";
- JPA学习---第五节:日期和枚举等字段类型的JPA映射
- Commons IO - IOUtils
- Android自定义UI的实现和应用
- 百度云是用SOUI开发的产品
- 有空就写个C++程序
- 在HTML页面中有jQuery实现实现拼图小游戏
- NPOI 的使用姿势
- Python对List中的元素排序
- sublime3 mac : Package Control There are no packages available for installation
- Arthas开源项目
- div中添加滚动条
- [分布式系统学习]阅读笔记 Distributed systems for fun and profit 抽象 之二
- 20145317《网络对抗》shellcode注入&;Return-to-libc攻击深入
热门文章
- StorSimple 简介
- cocos2d-x 添加自定义字体---中文,英文
- Android4.0 -- UI控件之 Menu 菜单的的使用(四)
- C#下多进程共同读写同一文件
- Mysql技术内幕-笔记-第三章 查询处理
- 我的第一篇Markdown博客
- js的 new image()用法[转]
- HDU 1568 Fibonacci 数学= = 开篇
- ffmpeg的logo, delogo滤镜参数设置
- [D3] 14. Line and Area Charts with D3