怎么生成批处理文件,并运行它?如有一个DOS程序,给它加上一些参数,再运行。应该怎么做呢?!请高手指教!!

解决方案 »

  1.   

    将命令输出到xx.bat的文本文件中,用shellexec来运行这个文件
    或用shellexec也可以直接将参数传给程序,
    类似命令还有createprocess,可以控制不显示dos窗口,以及得到其返回内容
      

  2.   

    var
      BatchFile: TextFile;
      BatchFileName: string;
      ProcessInfo: TProcessInformation;
      StartUpInfo: TStartupInfo;
    begin
      BatchFileName := ChangeFileExt(Paramstr(0),'.bat');
      AssignFile(BatchFile, BatchFileName);
      Rewrite(BatchFile);
      // build cmd batch file
      Writeln(BatchFile, 'dir');
      Writeln(BatchFile, 'cd\');
      ...
      CloseFile(BatchFile);
      FillChar(StartUpInfo, SizeOf(StartUpInfo), $00);
      StartUpInfo.dwFlags := STARTF_USESHOWWINDOW;
      StartUpInfo.wShowWindow := SW_HIDE;
      // create hidden process
      if CreateProcess(nil, PChar(BatchFileName), nil, nil,False, IDLE_PRIORITY_CLASS,
                       nil, nil, StartUpInfo,ProcessInfo) then
         begin
           CloseHandle(ProcessInfo.hThread);
           CloseHandle(ProcessInfo.hProcess);
         end;
    end;一个DOS程序,给它加上一些参数?
    ShellExecute或WinExec都可以,但WinExec没有那么多参数设置