runtime java examples

public static void main(String args[])throws IOException
{
    try
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter your git remote url");//Accepting URL
        String u=br.readLine();
        URL url=new URL(u);
        //System.out.println("Enter your commit sentence");//Commit line
        String commit="make it better";
        System.out.println("Get ready for your code to be on github in few minutes..");
        String comd[]=new String[6];
        comd[0]="git init";
        comd[1]="git add .";
        comd[2]="git commit -m \""+commit+"\"";
        comd[3]="git remote add origin "+url;
        comd[4]="git push -u origin master";
        //comd[4]="git push -f origin master"; // Sometimes harmful to execute without user prompt
        for(int i=0;i<5;i++)
        {
            String cmd=comd[i];
            Runtime run = Runtime.getRuntime();
            Process pr = run.exec(cmd);
            pr.waitFor();
            BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream()));
            String line = "";
            while ((line=buf.readLine())!=null) {
                System.out.println(line);
                //Error handling and force push prompts has to be handled
            }
        }
        System.out.println("Uploaded on github..");
    }catch(InterruptedException e){

    }
}
 

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source