[英]In Linux How to check through scripts what version of Java is installed?
[英]Check if Linux “Screen” package is installed
我需要一種方法來檢查是否安裝了 Linux 屏幕 package 但通過 Java 代碼安裝。 我想知道是否有內置的 function ? 此外,該解決方案必須與所有主要的 Linux 發行版和 MacOS 兼容。 有任何想法嗎?
如果您發出命令,請使用終端中的which screen
使用命令的退出值
which screen
echo Exitcode:$?
你得到
/usr/bin/screen
Exitcode:0
也適用於不存在的命令,
which screeeennn
echo Exitcode:$?
你得到
screeeennn not found
Exitcode:1
在 java class 中應用相同的邏輯
public class ScreenTest {
public static void main(String args[]) {
int exitValue;
try {
Process p = Runtime.getRuntime().exec("which screen");
exitValue = p.waitFor();
if (exitValue > 0) {
// not installed mostly value will be 1
} else {
//screen present value will be zero
}
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.