以前看过一篇相关文章,但找不到了,希望高人指点一二!

解决方案 »

  1.   

    procedure TForm1.Button1Click(Sender: TObject);
    begin
      winExec('c:\test.bat',0);end;procedure TForm1.Timer1Timer(Sender: TObject);
    begin
      if (fileExists('c:\test.txt')) then
        memo1.Lines.LoadFromFile('c:\test.txt');
    end;
      

  2.   

    以下是c:\test.bat的内容:rem--------------------
    @echo off
    dir c:\>c:\test.txt
    rem--------------------分数太少。
      

  3.   

    同意楼上,其实可以直接把命令些在WINEXEC里
      

  4.   

    "其实可以直接把命令些在WINEXEC里"错误!
    Dos内部命令是不能在 WinExec() 里执行的。
      

  5.   

    uses Shellapi;
    procedure TForm1.Button1Click(Sender: TObject);
    begin
    ShellExecute(handle,nil,pchar('c:\windows\123.bat'),nil,nil,sw_shownormal);
    end;
      

  6.   

    还是楼上的比较安全..最好用Shellexecute
      

  7.   

    unit Console;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls,ShellAPI;type
      TConsoleForm = class(TForm)
        btOpen: TButton;
        btClose: TButton;
        btRun: TButton;
        btOutput: TButton;
        procedure btOpenClick(Sender: TObject);
        procedure btCloseClick(Sender: TObject);
        procedure btOutputClick(Sender: TObject);
        procedure btRunClick(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      ConsoleForm: TConsoleForm;implementation{$R *.dfm}procedure TConsoleForm.btOpenClick(Sender: TObject);
    begin
      if not AllocConsole then Application.MessageBox('Can''t allocate console!','Console',MB_OK OR MB_ICONINFORMATION)
      else SetConsoleTitle('Console Demo');
    end;procedure TConsoleForm.btCloseClick(Sender: TObject);
    begin
      if not FreeConsole then Application.MessageBox('Can''t free console!','Console',MB_OK OR MB_ICONINFORMATION);
    end;procedure TConsoleForm.btOutputClick(Sender: TObject);
    var OutText:PChar;nWrite:Cardinal;sHandle:Cardinal;
    begin
     OutText:='Hello,console!'#$A#$D;
     sHandle:=GetStdHandle(STD_OUTPUT_HANDLE);
     if (sHandle<>0) then
     begin
       WriteConsole(sHandle,OutText,StrLen(OutText),nWrite,nil);
     end;
    end;procedure TConsoleForm.btRunClick(Sender: TObject);
    begin
      //这里要运行dos的dir命令,并将结果输出到"Open"按钮打开的Console 
      //Window,怎么写
    end;end.