[英]Batch file immediately terminates after executing a Java program (if batch file is called from another Java program)
[英]Java program terminates before completion of command in batch file
我試圖從Java程序中刪除批處理文件。
批處理文件有一個連接到IBM RTC的命令,然后獲取一些大約需要30秒的數據。
但是程序在命令運行后退出而不等待輸出。
public static void main(String[] args) {
final String scmCommand = "cmd /c D:\\Coverage\\SCMHistory.bat";
try {
Process process = Runtime.getRuntime().exec(scmCommand);
/*
* final InputStream in = process.getInputStream(); int ch;
* while((ch = in.read()) != -1) { System.out.print((char)ch); }
* final int returnCode = process.waitFor();
*/
try (final BufferedReader b = new BufferedReader(
new InputStreamReader(process.getInputStream()))) {
String line;
while ((line = b.readLine()) != null) {
System.out.println(line);
}
}
**System.out.println("waiting for the process");
process.waitFor();
System.out.println("waiting done");**
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
我試過添加process.waitFor();
但它沒有用。
set scm_path=D:\Coverage\RTC\jazz\scmtools\eclipse
set userId=ADMIN
set pwd=ADMIN
set repWorkspace="1081"
%scm_path%\scm show history -r https://rtc.repo.com:9443/jazz/ -u %userId% -P %pwd% -w "1411.201411" --component core_as D:\Work\201411\make\main_metadata.xml
Out put of which is
Change sets:
(3129) ----$ Sumit, HARI"main metadata is updated to deploy ch..." 03-Mar-2015 04:09 PM
(3130) ----$Sumit, HARI" "Fixed PartyID issue, checked in " 03-Mar-2015 01:01 PM
(3131) ----$ Sumit, HARI" "adding project to main_metada xml file" 26-Feb-2015 02:46 PM
使用start
用/w
或start /wait
選項在批處理文件運行程序。
例
Start "" /w program options ...
句法
START "title" [/D path] [options] "command" [parameters]
選項:
/W
或/WAIT
啟動應用程序並等待它終止。 (對於內部cmd命令或批處理文件,它運行CMD /K
)
您的批處理文件正在啟動一個新的控制台窗口並終止,即使您使用start而不是cmd。 還有/ c定義,
/ c執行string指定的命令,然后終止
試試這個,
final String scmCommand = "D:\\Coverage\\SCMHistory.bat";
如果這不起作用試試這個,
final String scmCommand = "D:\Coverage\RTC\jazz\scmtools\eclipse\scm";
String[] envp = new String[5];
envp[0] = "-r https://rtc.repo.com:9443/jazz/";
envp[1] = "-u ADMIN";
envp[2] = "-P ADMIN";
envp[3] = "-w \"1411.201411\" ";
envp[4] = "--component core_as D:\Work\201411\make\main_metadata.xml";
Process process = Runtime.getRuntime().exec(scmCommand, envp);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.