Q:

Java: Runtime.exec to get Linux distro name

I would like to check distro name, but I have got problem with bash executing command. Why this code works ok and print folder content
String cmd[] = {"ls","-a"};
Runtime run = Runtime.getRuntime(); 
try {
    Process proc = run.exec(cmd);
    BufferedReader read=new BufferedReader(new InputStreamReader(proc.getInputStream()));
    while(read.ready()) {
        System.out.println(read.readLine());
    }
} catch (IOException e) {
    e.printStackTrace();
}   

But cmd[] = {"cat","/etc/*-release"}; doesnt? It simply doesn't print anything, neither error nor distro. Ofc. it works in terminal. What is wrong with that?

A:

The reason it works in Bash is that Bash recognizes /etc/*-release as a glob and performs the necessary filename-expansion. Process doesn't do that; it just calls cat with the exact argument you specify. (In other words, you're running the equivalent of the Bash command cat '/etc/*-release'.)
One option, I suppose, is to actually call Bash and let it handle that for you:
String cmd[] = { "bash", "-c", "cat /etc/*-release" };

but I think it makes more sense to use the Java file-system API to search /etc for a file whose name ends in -release, and read that file's contents normally. (See the Javadoc for java.io.File and the Javadoc for java.io.FileReader.)

