Showing posts with label Lower level Operation. Show all posts
Showing posts with label Lower level Operation. Show all posts

Saturday, September 27, 2014

Example 2



public class RunCmd
{
    public static void main(String[] args)
    {
        Process P;
        Runtime r;
        r = Runtime.getRuntime();
        try {
            String cmd = new String();
            cmd ="C:\\db2sqlloader\\run_dir.bat";
//       ;
           
           
            try {
                P = r.exec(cmd);
                int Exitcode = P.waitFor();
                if (Exitcode != 0)
                {
                    System.out.println("The command line job did not execute successfully");
                }
                else
                {
                    System.out.println("The command line job - " +
                             " - executed successfully."); //break
                }
                       
            }
            catch (Exception e)
                       
            {
                System.out.println(" 1 e.getMessage():"+e.getMessage());
            }
        } catch (Exception e)
        {
            System.out.println("2 e.getMessage():"+e.getMessage());
        }
    }
}

Java Operation on lower level example 1



import java.io.*;
import java.sql.*;
import java.util.StringTokenizer;
import org.apache.commons.cli.*;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.log4j.Logger;

public class Process1 {

    public static void Process1(String args[])

    {
        Runtime runtime = Runtime.getRuntime();
        try {
            Process p1 = runtime.exec("cmd /c start C:\\db2sqlloader\\run_dir.bat");
            InputStream is = p1.getInputStream();
            int i = 0;
            while ((i = is.read()) != -1) {
                System.out.print((char) i);
            }
        } catch (IOException ioException) {
            System.out.println(ioException.getMessage());
        }
    }
}