JAvaプログラムはbatファイルを呼び出しoracelデータベースバックアップを実行する


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * java    bat  ,  oracel     
 * @author PanHongBin */
public class ExpOracleData {
	
	/**
	 * @param args
	 */
	public static void main( String[] args ){
		ExpOracleData expOracleData = new ExpOracleData( );
		expOracleData.run( );
	}
	
	public void run( ){
		try{
			String cmd = "cmd.exe /c G:/dmp/expOracleData.bat";
			Process process = Runtime.getRuntime( ).exec( cmd );
			ThreadInputStream inputStream = new ThreadInputStream( process );
			ThreadErrorStream errorStream = new ThreadErrorStream( process );
			inputStream.start( );
			errorStream.start( );
			if ( process.waitFor( ) == 0 ){
				System.out.println( "  " );
			}
			else{
				System.out.println( "    *****" );
			}
			if ( process.exitValue( ) == 0 ){
				System.out.println( "      。" );
				System.out.println( "            " );
				// save();
			}
			else{
				System.out.println( "      !" );
			}
		}
		catch ( Exception e ){
			e.printStackTrace( );
		}
		System.out.println( "  " );
	}
}

class ThreadInputStream extends Thread {
	
	Process process = null;
	
	public ThreadInputStream( Process process ){
		this.process = process;
	}
	
	public void run( ){
		InputStream inputStream = process.getInputStream( );
		BufferedReader bufferedReader = new BufferedReader( new InputStreamReader( inputStream ) );
		try{
			String line = null;
			while ( ( line = bufferedReader.readLine( ) ) != null ){
				if ( line != null ){
					System.out.println( line );
					if ( line.indexOf( "exp" ) != -1 ){
						System.out.println( "        " );
						break;
					}
				}
			}
			System.out.println( "    ^^^^^^" );
		}
		catch ( IOException e ){
			e.printStackTrace( );
		}
	}
}

class ThreadErrorStream extends Thread {
	
	Process process = null;
	
	public ThreadErrorStream( Process process ){
		this.process = process;
	}
	
	public void run( ){
		InputStream errorStream = process.getErrorStream( );
		BufferedReader bufferedReader = new BufferedReader( new InputStreamReader( errorStream ) );
		try{
			String line = null;
			while ( ( line = bufferedReader.readLine( ) ) != null ){
				if ( line != null ){
					System.out.println( line );
					if ( line.indexOf( "      " ) != -1 ){
						System.out.println( "      -------" );
					}
					if ( line.indexOf( "ORA-01017" ) != -1 ){
						System.out.println( "    /       ORA-01017-------" );
						process.destroy( );
						break;
					}
					if ( line.indexOf( "EXP-00028" ) != -1 ){
						System.out.println( "      :EXP-00028-------" );
						process.destroy( );
						break;
					}
				}
			}
			System.out.println( "     ^^^^^^" );
		}
		catch ( IOException e ){
			e.printStackTrace( );
		}
	}
}