1
我希望能够在Mac OS和使用相同的Java应用程序在Windows系统中的.bat文件运行.SH。 有没有办法做到这一点? 在此先感谢。分别运行.bat文件和sh文件取决于操作系统
我希望能够在Mac OS和使用相同的Java应用程序在Windows系统中的.bat文件运行.SH。 有没有办法做到这一点? 在此先感谢。分别运行.bat文件和sh文件取决于操作系统
有寻找操作系统... Java中的内置API。
System.getProperty("os.name");
。
然后,您可以编写一个case
或if else
。像...
private String os = System.getProperty("os.name").toLowerCase();
if (os.contains("windows"){
p = Runtime.getRuntime().exec("your batch file");
p.waitFor();
} else if (os.contains("mac"){
p = Runtime.getRuntime().exec("your sh file or dmg");
p.waitFor();
} else {
p = Runtime.getRuntime().exec("your .sh file");
p.waitFor();
}
/**
* @Reff http://www.tutorialspoint.com/java/lang/system_getproperties.htm
*/
import java.lang.String;
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
String os = System.getProperty("os.name").toString();
System.out.println("OS: " + os);
if("Windows 8".equals(os)) {
System.out.println("Windows 8");
} else {
System.out.println("Others");
}
}
}