「Java開発」Java外部コマンド(java cmd)を実行するサンプルコード

Javaコード:

Process process = Runtime.getRuntime().exec(“D:\\startnews24_javacmd.bat"); // システムコマンドを実行
InputStream fis = process.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
String line = null;
StringBuffer cmdout = new StringBuffer();
while ((line = br.readLine()) != null) {
cmdout.append(line).append(System.getProperty(“line.separator"));
}
br.close();
process.destroy();
System.out.print(cmdout.toString().trim());
int result = 0;
if (cmdout.toString().contains(“BUILD SUCCESS")) {
result = 1;
System.out.println(“\n" + “result =" + result);
}
System.out.print(“—-" + System.getProperty(“line.separator"));

Java

Posted by arkgame