何判断一个bat文件是否已执行结束

解决方案 »

  1.   

    >>在bat结束的时候写一个文件吧,检测文件是否存在就可以了。   
        
      如果这样的话,在bat开始的时候要del这个文件   
        
      if   exists   filename   then   del   filename   
      rem   other   operations   
        
        
      rem   end   of   other   operations   
      if   not   exists   filename   then   copy   nul   filename
      

  2.   

    如果BAT文件配合一下,应该是可以的,可以让BAT文件每执行一步,向一个文件里面写入一个标记,然后调用程序不停的读取这个文件,设置进度。
      

  3.   


    举个例子吧,省的我去百度 GOOGLE的了
      

  4.   

    http://blog.csdn.net/eulb/archive/2007/04/29/1591559.aspx
      

  5.   

    不好意思,上面的代码不是delphi的function WinExecAndWait32_v1(FileName: string; Visibility: integer): Cardinal;
    var
      zAppName: array[0..512] of char;
      zCurDir: array[0..255] of char;
      WorkDir: string;
      StartupInfo: TStartupInfo;
      ProcessInfo: TProcessInformation;
    begin
      StrPCopy(zAppName, FileName);
      GetDir(0, WorkDir);
      StrPCopy(zCurDir, WorkDir);
      FillChar(StartupInfo, Sizeof(StartupInfo), #0);
      StartupInfo.cb := Sizeof(StartupInfo);
      StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
      StartupInfo.wShowWindow := Visibility;
      if not CreateProcess(nil,
        zAppName,               { pointer to command line string }
        nil,                    { pointer to process security attributes }
        nil,                    { pointer to thread security attributes }
        true,                   { handle inheritance flag }
        CREATE_NEW_CONSOLE or   { creation flags }
        NORMAL_PRIORITY_CLASS,
        nil,                    { pointer to new environment block }
        nil,                    { pointer to current directory name, PChar}
        StartupInfo,            { pointer to STARTUPINFO }
        ProcessInfo)            { pointer to PROCESS_INF }
        then Result := INFINITE {-1} else
      begin
        WaitforSingleObject(ProcessInfo.hProcess, INFINITE);
        GetExitCodeProcess(ProcessInfo.hProcess, Result);
        CloseHandle(ProcessInfo.hProcess);  { to prevent memory leaks }
        CloseHandle(ProcessInfo.hThread);
      end;
    end;//调用方法
    WinExecAndWait32_v1('c:\a.bat ', SW_NORMAL);
    不过我试着还有问题
      

  6.   

    没有问题
    之前我测试的del命令,忘了进入到指定路径了
      

  7.   

    bat文件执行时会有新的进程或线程启动
    可以利用WaitForSingleObject这个API函数来实现对进程或者线程的等待,直到它返回。
    is that clear?