Created
June 4, 2017 13:23
-
-
Save dynamitechetan/e879b8509e48682c0f9994e3201ea7ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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