Skip to content

Instantly share code, notes, and snippets.

@RobertApikyan
Created October 24, 2019 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RobertApikyan/f0fafe7e58c03a174774edfc87faae5b to your computer and use it in GitHub Desktop.
Save RobertApikyan/f0fafe7e58c03a174774edfc87faae5b to your computer and use it in GitHub Desktop.
public class Test {
public static void main(String[] args) {
BashRunner.run("git help");
}
public static class BashRunner {
private static final Logger log = Logger.getLogger(BashRunner.class.getName());
public static void run(String comand) {
Runtime run = Runtime.getRuntime();
try {
Process proc = run.exec(new String[]{"C:/cygwin64/bin/bash.exe", "-c", comand});
proc.waitFor();
BufferedReader br = new BufferedReader(new InputStreamReader(
proc.getInputStream()));
while (br.ready())
System.out.println(br.readLine());
} catch (Exception e) {
log.log(Level.SEVERE, "failed " + comand + " ", e);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment