Skip to content

Instantly share code, notes, and snippets.

@dynamitechetan
Created June 4, 2017 13:23
Show Gist options
  • Save dynamitechetan/e879b8509e48682c0f9994e3201ea7ed to your computer and use it in GitHub Desktop.
Save dynamitechetan/e879b8509e48682c0f9994e3201ea7ed to your computer and use it in GitHub Desktop.
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class VCSOperations {
public static void main(String[] args) {
VCSOperations obj = new VCSOperations();
// write some git commands here
// for example git init, replace it with the command you want.
String command = "git init";
String output = obj.executeCommand(command);
System.out.println(output);
}
private String executeCommand(String command) {
StringBuffer output = new StringBuffer();
Process p;
try {
p = Runtime.getRuntime().exec(command);
p.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
while ((line = reader.readLine())!= null) {
output.append(line + "\n");
}
} catch (Exception e) {
e.printStackTrace();
}
return output.toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment