windows笔记(服务安装,sqlserver命令行,java调用bat脚本)

1.服务安装: 例如tomcat

 

在tomcat可以启动的前提下,service install tomcat

 

 

2.sqlserver命令行

 

使用osql工具,安装sqlserver后直接在cmd下运行osql命令 osql -?查看命令使用方法

 

3.java调用bat脚本(记得输出inpubStream,否则线程阻塞)

 

使用Runtime.getRuntime().exec

 

 

public void runbat(String timeFortmat) {
		String cmd = "cmd /c C://" + timeFortmat + ".bat";
		Runtime runtime = Runtime.getRuntime();
		Process child = null; 
		try {
			child = runtime.exec(cmd);
			InputStream in = child.getInputStream();
			String output = null;
			int isSuccessful = 0;
			BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in)); 

			output=bufferedReader.readLine(); 

			while(output!= null){ 

				System.out.println(output); 

				output=bufferedReader.readLine(); 

			} 

			
			try {
				//isSuccessful = child.waitFor();
			} catch (Exception e) {
				e.printStackTrace();
			} 

		} catch (IOException ioe) {
			ioe.printStackTrace();
		}finally{
			child.destroy();
		}
		System.out.println("------------>ok");
	}
 

你可能感兴趣的:(java,tomcat,c,windows,脚本)