[英]run c program by java program on windows
我有一個用於圖形用戶界面的Java程序。 該Java程序運行已編譯的C程序。 我創建一個JAR文件以使程序可執行。 結果,我的C程序包含在JAR文件中。
我用這些行:
String[] Tab_arg =new String[6];
Tab_arg[0]="./src/generalisation.exe";
Tab_arg[1]=fileM.getAbsolutePath();
Tab_arg[2]=fileG.getAbsolutePath();
Tab_arg[3]=fichGA_absolutePath;
Tab_arg[4]=fichGO_absolutePath;
Tab_arg[5]=fileR.getAbsolutePath();
try
{
Process p =Runtime.getRuntime().exec(Tab_arg);
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) System.out.println(inputLine);
}
catch (IOException e)
{
e.printStackTrace();
}
問題是JAR文件在Ubuntu上可以正常運行,但在Windows上不能正常運行。
為Windows編譯后,可以將兩個版本(Linux和Windows)添加到JAR文件中。 在您的代碼中,您可以添加
if(System.getProperty("os.name").startsWith("Windows"))
Tab_arg[0]=".\src\generalisation.exe";
else
Tab_arg[0]="./src/generalisation";
如果Linux版本沒有擴展名,這應該可以解決問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.