比如dir c:\

解决方案 »

  1.   

    一种方法,先输出到文件,再读取:
    ShellExecute(0, nil, 'cmd', '/c dir c:\ > c:\z.txt', nil, SW_HIDE);
    Memo1.Lines.LoadFromFile('c:\z.txt');
    DeleteFile('c:\z.txt');还一种是不用ShellExecute,用CreateProcess,挺麻烦的说。
      

  2.   

    不要弹出“命令提示符”窗口和手工输入命令,ShellExecute(0, nil, 'dir', 'c:\ > c:\z.txt', nil, SW_HIDE);为何得不到z.txt文件?
      

  3.   

    你写错了,第三个参数应该用cmd (Win98用command):
    ShellExecute(0, nil, 'cmd', 'dir c:\ > c:\z.txt', nil, SW_HIDE);
      

  4.   

    只是测试用的
    procedure TForm1.Button2Click(Sender: TObject);
    begin
     ShellExecute(0, nil, 'cmd', 'dir c:\ > c:\z.txt', nil, SW_HIDE);
    end;
      

  5.   

    刚才没注意,少了参数/c :
    procedure TForm1.Button2Click(Sender: TObject);
    begin
     ShellExecute(0, nil, 'cmd', '/c dir c:\ > c:\z.txt', nil, SW_HIDE);
    end;
    参数/c意义:
    /c  执行字符串指定的命令然后终断(关闭DOS窗口)
      

  6.   

    如果命令行中的参数是由外部变量传递的,应如何做?比如dir c:\,c:\是由变量传递的