DELPHI盒子
!实时搜索: 盒子论坛 | 注册用户 | 修改信息 | 退出
检举帖 | 全文检索 | 关闭广告 | 捐赠
技术论坛
 用户名
 密  码
自动登陆(30天有效)
忘了密码
≡技术区≡
DELPHI技术
lazarus/fpc/Free Pascal
移动应用开发
Web应用开发
数据库专区
报表专区
网络通讯
开源项目
论坛精华贴
≡发布区≡
发布代码
发布控件
文档资料
经典工具
≡事务区≡
网站意见
盒子之家
招聘应聘
信息交换
论坛信息
最新加入: laidabin
今日帖子: 6
在线用户: 33
导航: 论坛 -> DELPHI技术 斑竹:liumazi,sephil  
作者:
男 like11011 (nannan) ▲▲▲▲△ -
普通会员
2017/7/23 12:54:57
标题:
有会用Turbo Pack Doscommand控件的吗,请进来指点一下 浏览:1675
加入我的收藏
楼主: 组件网址:https://raw.githubusercontent.com/TurboPack/DOSCommand/master/Source/DosCommand.pas
为什么会有好多重复项.
procedure TForm6.Button1Click(Sender: TObject);
begin
  Memo1.Lines.Clear;
  doscmd := TDosCommand.Create(nil);
  doscmd.CurrentDir := GetCurrentDir();
  doscmd.CommandLine := 'cmd /c dir';
  doscmd.OutputLines := Memo1.Lines;
  doscmd.Execute;
end;
此帖子包含附件:
JPEG 图像
大小:32.3K
----------------------------------------------
-
作者:
男 epzybook (epzybook) ★☆☆☆☆ -
普通会员
2017/7/23 14:11:26
1楼: 晕,这个还用控件?
----------------------------------------------
-
作者:
男 xuchuantao (暗黑天使) ★☆☆☆☆ -
普通会员
2017/7/23 19:27:43
2楼: doscmd := TDosCommand.Create(nil);
  doscmd.CurrentDir := GetCurrentDir();
  doscmd.CommandLine := 'cmd.exe';doscmd.SendLine('/c dir', True);
  doscmd.OutputLines := Memo1.Lines;
  doscmd.Execute;
例子代码里面有https://github.com/TurboPack/DOSCommand/blob/master/Source/DosCommand.pas
----------------------------------------------
按此在新窗口浏览图片
作者:
男 bjlg (蓝天) ★☆☆☆☆ -
盒子活跃会员
2017/7/24 0:24:18
3楼: 这个本身就是有bug的
----------------------------------------------
http://delphi.icm.edu.pl/ftp/http://delphi-z.ru
作者:
男 xlnrony (xlnrony) ★☆☆☆☆ -
盒子活跃会员
2017/7/24 8:25:19
4楼: function RunCmd(const CmdLine, WorkDir, stdin: string): string;
var
  StdInRead, StdInWrite: THandle;
  StdOutRead, StdOutWrite: THandle;
  StartInfo: TStartupInfo;
  ProcInfo: TProcessInformation;
  SA: TSecurityAttributes;
  HandleStream: THandleStream;
  StringStream: TStringStream;
  RetStrs: TStrings;
  ExitCode: DWORD;
  procedure DoCmd;
  begin
    FillChar(StartInfo, sizeof(StartInfo), 0);
    StartInfo.cb := sizeof(StartInfo);
    StartInfo.wShowWindow := SW_HIDE;
    // 使用指定的句柄作为标准输入输出的文件句柄,使用指定的显示方式
    StartInfo.dwFlags := STARTF_USESTDHANDLES or STARTF_USESHOWWINDOW;
    StartInfo.hStdError := StdOutWrite;
    StartInfo.hStdInput := StdInRead;
    StartInfo.hStdOutput := StdOutWrite;

    if not CreateProcess(nil, // lpApplicationName: PChar
      PChar(CmdLine), // lpCommandLine: PChar
      nil, // lpProcessAttributes: PSecurityAttributes
      nil, // lpThreadAttributes: PSecurityAttributes
      True, // bInheritHandles: BOOL
      CREATE_NEW_CONSOLE, nil, PChar(WorkDir), StartInfo, ProcInfo) then
    begin
      raise Exception.Create(SysErrorMessage(GetLastError));
    end;
    try
      WaitForSingleObject(ProcInfo.hProcess, INFINITE);

      HandleStream := THandleStream.Create(StdOutRead);
      try
        if HandleStream.Size > 0 then
        begin
          RetStrs := TStringList.Create;
          try
          RetStrs.LoadFromStream(HandleStream);
          Result := RetStrs.Text;
          finally
          RetStrs.Free;
          end;
        end;
      finally
        HandleStream.Free;
      end;

      if not GetExitCodeProcess(ProcInfo.hProcess, ExitCode) then
      begin
        raise Exception.Create(SysErrorMessage(GetLastError));
      end;
      if ExitCode <> 0 then
      begin
        raise Exception.Create(Result);
      end;
    finally
      CloseHandle(ProcInfo.hThread);
      CloseHandle(ProcInfo.hProcess);
    end;
  end;

begin
  Result := '';
  FillChar(SA, sizeof(SA), 0);
  // 设置允许继承,否则在NT和2000下无法取得输出结果
  SA.nLength := sizeof(SA);
  SA.bInheritHandle := True;
  SA.lpSecurityDescriptor := nil;

  if not CreatePipe(StdOutRead, StdOutWrite, @SA, 0) then
  begin
    raise Exception.Create(SysErrorMessage(GetLastError));
  end;
  try
    if Length(stdin) <> 0 then
    begin
      if not CreatePipe(StdInRead, StdInWrite, @SA, 0) then
      begin
        raise Exception.Create(SysErrorMessage(GetLastError));
      end;
      try
        HandleStream := THandleStream.Create(StdInWrite);
        try
          StringStream := TStringStream.Create(stdin);
          try
          HandleStream.CopyFrom(StringStream, 0);
          finally
          StringStream.Free;
          end;
        finally
          HandleStream.Free;
        end;

        DoCmd;
      finally
        CloseHandle(StdInRead);
        CloseHandle(StdInWrite);
      end;
    end
    else
    begin
      StdInRead := GetStdHandle(STD_INPUT_HANDLE);
      DoCmd;
    end;
  finally
    CloseHandle(StdOutRead);
    CloseHandle(StdOutWrite);
  end;
end;
拿去按此在新窗口浏览图片 按此在新窗口浏览图片 按此在新窗口浏览图片 按此在新窗口浏览图片 按此在新窗口浏览图片 按此在新窗口浏览图片 按此在新窗口浏览图片
----------------------------------------------
-
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v3.0.1 版权所有 页面执行89.84375毫秒 RSS