@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不就好了?
在1.bat执行完以后,再掉用2.bat文件啊! 没做过bat扩展码的程序
直接在1.bat末尾又调用2.bat文件
在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(); }
按你说的 bat2不是需要bat1执行后才可以执行么
的内容加到bat1中去啊,怎么了呢?
或者这样好了,用状态文件,bat1执行完后在约定的位置产生一个文件,
然后bat2执行时先判断状态文件存在与否,若无,则等待呗,这样好了?
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不就好了?
没做过bat扩展码的程序
//用进程执行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();
}
你试试这么做 在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
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);
}
}