Skip to content

Instantly share code, notes, and snippets.

Created October 1, 2012 07:45
Show Gist options
  • Select an option

  • Save anonymous/3810155 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/3810155 to your computer and use it in GitHub Desktop.
public static String system(String cmds) {
String value = "";
try {
String cmd[] = { "/bin/sh", "-c", cmds};
Process p = Runtime.getRuntime().exec(cmd);
p.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = reader.readLine();
while (line != null) {
value += line + "\n\r";
line = reader.readLine();
}
}
catch (IOException ioe) {
ioe.printStackTrace();
}
catch (InterruptedException ie) {
ie.printStackTrace();
}
return value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment