Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This code can help you:</p> <pre><code>String[] cmd = { "/bin/sh", "-c", "cat /etc/*-release" }; try { Process p = Runtime.getRuntime().exec(cmd); BufferedReader bri = new BufferedReader(new InputStreamReader( p.getInputStream())); String line = ""; while ((line = bri.readLine()) != null) { System.out.println(line); } } catch (IOException e) { e.printStackTrace(); } </code></pre> <p><strong>UPDATE</strong></p> <p>It if you only need the version try with uname -a </p> <p><strong>UPDATE</strong></p> <p>Some linux distros contain the distro version in the /proc/version file. Here is an example to print them all from java without invoking any SO commands</p> <pre><code>//lists all the files ending with -release in the etc folder File dir = new File("/etc/"); File fileList[] = new File[0]; if(dir.exists()){ fileList = dir.listFiles(new FilenameFilter() { public boolean accept(File dir, String filename) { return filename.endsWith("-release"); } }); } //looks for the version file (not all linux distros) File fileVersion = new File("/proc/version"); if(fileVersion.exists()){ fileList = Arrays.copyOf(fileList,fileList.length+1); fileList[fileList.length-1] = fileVersion; } //prints all the version-related files for (File f : fileList) { try { BufferedReader myReader = new BufferedReader(new FileReader(f)); String strLine = null; while ((strLine = myReader.readLine()) != null) { System.out.println(strLine); } myReader.close(); } catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload