How to programatically check if a software utility is installed on ubuntu using Java

前端 未结 3 1674
眼角桃花
眼角桃花 2021-01-28 23:34

I am working on a Java Project for my own learning, what i have made is a class which can both read and write to external process using Runtime.getRuntime().exec(cmd);

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-28 23:50

    I am not aware of any tool that could help if package management tool does not report installation correctly. It could be that the some tools are installed but not updated the database.

    It may be useful to check if your target executable exists in any directories in $PATH and standard location.

      String pathString = System.getenv("PATH");
       String[]  dirs= pathString.split(':');
       String[]  exes= { "name1", "name2" ....};
    
       for ( String exename : exes) {
         for ( String dirname : dirs) {
                 File exeFile=new File( dirname, exename);
                 //do some checks if file exists etc.
         }
       }
    

提交回复
热议问题