Skip to content

Instantly share code, notes, and snippets.

@xonixx
Created September 22, 2023 15:40
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 xonixx/cb0944413f7ccc22f2b295b392ecef83 to your computer and use it in GitHub Desktop.
Save xonixx/cb0944413f7ccc22f2b295b392ecef83 to your computer and use it in GitHub Desktop.
try {
Process process = Runtime.getRuntime().exec(new String[]{"ls", "-l", fullPath});
process.waitFor();
java.util.Scanner s = new java.util.Scanner(process.getInputStream()).useDelimiter("\\A");
String result = s.hasNext() ? s.next() : "";
System.out.println(result);
s = new java.util.Scanner(process.getErrorStream()).useDelimiter("\\A");
result = s.hasNext() ? s.next() : "";
System.out.println(result);
} catch (Exception e) {
e.printStackTrace();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment