我有两个批处理1.bat和2.bat,必须要将1.bat执行完之后调用2.bat,不过1.bat执行需要执行一些系统命令,所以大概要执行10秒钟左右,如果程序流水式的执行下来,到2.bat时1.bat中的那些命令还没有执行完,如何解决这个问题,保证1.bat中的那些命令执行完毕后再执行2.bat,谢谢!

解决方案 »

  1.   

    那就先执行1.BAT呗,完了之后再2.bat,也用不到多线程呀
      

  2.   

    1.bat调用一些系统的命令,我手动运行1.bat时那个dos窗口停在那有10多秒,所以在这10几秒时间内运行2.bat就失败了..
      

  3.   

    放一起不行么
    按你说的 bat2不是需要bat1执行后才可以执行么
      

  4.   

    关键就是这个啊,1里面有很多命令,会停顿较长时间啊,在这期间是不能运行2.bat的。。
      

  5.   

    真搞不懂楼主啥意思,若是bat1和bat2是顺序执行的,那大可将bat2
    的内容加到bat1中去啊,怎么了呢?
    或者这样好了,用状态文件,bat1执行完后在约定的位置产生一个文件,
    然后bat2执行时先判断状态文件存在与否,若无,则等待呗,这样好了?
      

  6.   

    可以使用java的进程来执行,然后解析流判断。
      

  7.   

    @echo off
    rem Licensed to the Apache Software Foundation (ASF) under one or more
    rem contributor license agreements.  See the NOTICE file distributed with
    rem this work for additional information regarding copyright ownership.
    rem The ASF licenses this file to You under the Apache License, Version 2.0
    rem (the "License"); you may not use this file except in compliance with
    rem the License.  You may obtain a copy of the License at
    rem
    rem     http://www.apache.org/licenses/LICENSE-2.0
    rem
    rem Unless required by applicable law or agreed to in writing, software
    rem distributed under the License is distributed on an "AS IS" BASIS,
    rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    rem See the License for the specific language governing permissions and
    rem limitations under the License.if "%OS%" == "Windows_NT" setlocal
    rem ---------------------------------------------------------------------------
    rem Start script for the CATALINA Server
    rem
    rem $Id: startup.bat 908749 2010-02-10 23:26:42Z t $
    rem ---------------------------------------------------------------------------rem Guess CATALINA_HOME if not defined
    set "CURRENT_DIR=%cd%"
    if not "%CATALINA_HOME%" == "" goto gotHome
    set "CATALINA_HOME=%CURRENT_DIR%"
    if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
    cd ..
    set "CATALINA_HOME=%cd%"
    cd "%CURRENT_DIR%"
    :gotHome
    if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
    echo The CATALINA_HOME environment variable is not defined correctly
    echo This environment variable is needed to run this program
    goto end
    :okHomeset "EXECUTABLE=%CATALINA_HOME%\bin\catalina.bat"rem Check that target executable exists
    if exist "%EXECUTABLE%" goto okExec
    echo Cannot find "%EXECUTABLE%"
    echo This file is needed to run this program
    goto end
    :okExecrem Get remaining unshifted command line arguments and save them in the
    set CMD_LINE_ARGS=
    :setArgs
    if ""%1""=="""" goto doneSetArgs
    set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
    shift
    goto setArgs
    :doneSetArgscall "%EXECUTABLE%" start %CMD_LINE_ARGS%:endbat1执行完成之后调用bat2不就好了?
      

  8.   

    在1.bat执行完以后,再掉用2.bat文件啊!
        没做过bat扩展码的程序
      

  9.   

    直接在1.bat末尾又调用2.bat文件
      

  10.   

    在cmd窗口下,需要保证1.bat和2.bat能执行,否则需要更改一下~~~ try {
    //用进程执行1.bat
    Process process = Runtime.getRuntime().exec("1.bat");
    //当前的线程中断,直到process执行完毕
    process.waitFor();
    //用线程执行2.bat
    process = Runtime.getRuntime().exec("2.bat");
    process.waitFor();
    } catch (IOException e) {
    e.printStackTrace();
    } catch (InterruptedException e) {
    e.printStackTrace();
    }
      

  11.   


    你试试这么做 在1.bat文件最后加入一句dos命令:在C盘下创建一个文件“1.batFinish”在java程序中,建一个线程。线程的功能是 1s钟一次监控C盘是否存在1.batFinish所以
    1.执行1.bat前先用java程序删除c:/1.batFinish
    2.启动监控线程
    3.运行1.bat
    4.监控线程一旦发现存在1.batFinish 立即运行2.bat
      

  12.   

    你试试大概这么写
    public void run(){
      File f= new File("c:1.batFinish");
          if(f.exists()){
      f.delete();
          }
          Runtime.getRuntime().exec("2.bat");

      while(true){
          f= new File("c:1.batFinish");
          if(f.exists()){
      Runtime.getRuntime().exec("2.bat");
      break;
          }
          TimeUnit.MICROSECONDS.sleep(1000);
      }
    }