runtime java examples

Solutions on MaxInterview for runtime java examples by the best coders in the world

showing results for - "runtime java examples"
Victoria
09 Jan 2019
1public static void main(String args[])throws IOException
2{
3    try
4    {
5        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
6        System.out.println("Enter your git remote url");//Accepting URL
7        String u=br.readLine();
8        URL url=new URL(u);
9        //System.out.println("Enter your commit sentence");//Commit line
10        String commit="make it better";
11        System.out.println("Get ready for your code to be on github in few minutes..");
12        String comd[]=new String[6];
13        comd[0]="git init";
14        comd[1]="git add .";
15        comd[2]="git commit -m \""+commit+"\"";
16        comd[3]="git remote add origin "+url;
17        comd[4]="git push -u origin master";
18        //comd[4]="git push -f origin master"; // Sometimes harmful to execute without user prompt
19        for(int i=0;i<5;i++)
20        {
21            String cmd=comd[i];
22            Runtime run = Runtime.getRuntime();
23            Process pr = run.exec(cmd);
24            pr.waitFor();
25            BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream()));
26            String line = "";
27            while ((line=buf.readLine())!=null) {
28                System.out.println(line);
29                //Error handling and force push prompts has to be handled
30            }
31        }
32        System.out.println("Uploaded on github..");
33    }catch(InterruptedException e){
34
35    }
36}
37