0

I have a Java program for the graphical user interface. This Java program runs a C program which is already compiled. I create a JAR file in order to make my program executable. As a consequence my C program is included in the JAR file.

I use those lines :

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();
}

The trouble is that the JAR file operates correctly on Ubuntu but not on Windows.

4
  • Well, did you compile the C program for Windows? Commented Aug 27, 2012 at 14:31
  • No, the C program is compiled on Ubuntu. You mean, I should create another executable : one for Windows and this other for Ubuntu ? Commented Aug 27, 2012 at 14:35
  • 2
    Yes you should make 2 executables and check in the javacode which one to run. Windows and linux have a different executable format and different API's so there is no way the Ubuntu C program could run on Windows without proper emulation. Commented Aug 27, 2012 at 14:39
  • ok ! And, the way to run the Windows executable stills "./XXX" ?! Commented Aug 27, 2012 at 14:43

1 Answer 1

1

When you have compiled it for Windows, you could add the two versions (Linux and Windows) to the JAR file. In your code you could add this

if(System.getProperty("os.name").startsWith("Windows"))
    Tab_arg[0]=".\src\generalisation.exe";
else
    Tab_arg[0]="./src/generalisation";

This should do the trick if the Linux version has no extension.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.