Java执行bat脚本
public void upload() throws IOException {
String scriptPath = "D:\\NLZ_HD\\solrCloud\\uploadToZookeeper.bat";
Process process = Runtime.getRuntime().exec(scriptPath);
System.out.println("上传配置到zookeeper");
//将cmd的执行结果通过java的IO流输出到IDE的控制台
//InputStream is = process.getInputStream();
//InputStreamReader isr = new InputStreamReader(is,"GBK");
//BufferedReader br = new BufferedReader(isr);
//String content = br.readLine();
//while (content != null) {
// System.out.println(content);
// content = br.readLine();
//}
}
D:
cd D:\NLZ_HD\solrCloud\solr-5.3.1\server\scripts\cloud-scripts\
#使用call可以在bat文件中调用其他bat
call zkcli.bat -zkhost 127.0.0.1:2181 -cmd putfile /configs/collectionxConf/dynamicdic.txt D:\NLZ_HD\solrCloud\solrhome01\collection1\collectionxConf\dynamicdic.txt
call zkcli.bat -zkhost 127.0.0.1:2181 -cmd putfile /configs/collectionxConf/synonyms.txt D:\NLZ_HD\solrCloud\solrhome01\collection1\collectionxConf\synonyms.txt
call zkcli.bat -zkhost 127.0.0.1:2181 -cmd putfile /configs/collectionxConf/stopword.dic D:\NLZ_HD\solrCloud\solrhome01\collection1\collectionxConf\stopword.dic
call zkcli.bat -zkhost 127.0.0.1:2181 -cmd putfile /configs/collectionxConf/ik.conf D:\NLZ_HD\solrCloud\solrhome01\collection1\collectionxConf\ik.conf
echo update successful.