Click here to Skip to main content
15,880,503 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
hi everyine!

I have 2 applications one coded in C++ and the other coded in java, i want to launch the one coded in c++ from the other one, honnestly i dont know how to do it at all

any ideas about that???

thank YOU very much for any help
Posted
Comments
[no name] 9-Sep-13 22:37pm    
This question not well worded - it is about running any exe from Java - how the exe is created is not important. Google it and you will be overwhelmed. Here's a start
http://stackoverflow.com/questions/5604698/java-programming-call-an-exe-from-java-and-passing-parameters

1 solution

You want to ask Google about Runtime[^]. Here is some code I use to do that kind of thing:

Java
protected Process DoSysCommand(String sCmd, boolean bWait)
{
    Runtime r = Runtime.getRuntime();
    Process retP = null;
    try
    {
        retP = r.exec(sCmd);
        if(bWait)
        {
            retP.waitFor();
        }
    }
    catch(IOException e)
    {
        System.err.println(e.getMessage());
    }
    catch(InterruptedException e)
    {
        System.err.println(e.getMessage());
    }
    return retP;
}
 
Share this answer
 
Comments
Manel1989 10-Sep-13 14:02pm    
thank you for your answer, i tryed to do it by this code but it doesn't work : this is my code
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec(new String[]{"Microsoft Visual C++ 2010 Express.exe", "readxmlresou.exe"}, null, new File("C:\\Users\\abdelhalim\\Desktop\\"));

the compiler get me this error :
Exception in thread "main" java.io.IOException: Cannot run program "MicrosoftVisualC++2010Express.exe" (in directory "C:\Users\abdelhalim\Desktop"): CreateProcess error=2,The specified file is not found
and im sur that i have "readxmlresou.exe" in that directory??????
H.Brydon 10-Sep-13 23:25pm    
Messages can be deceiving but the computer does not lie. If it says that it can't find a file, then that is the case.
Manel1989 11-Sep-13 21:03pm    
Thank YOU for your help,
But whene i use this code :
Process process = new ProcessBuilder("C:\\Visual Studio 2010\\Projects\\readxmlresou\\Debug\\readxmlresou.exe").start();

there is no errors but the program doesn't excute either !!!!!
Do i miss any thing here ???????

Thank YOU again for help
H.Brydon 11-Sep-13 22:39pm    
How do you know it does not execute? I haven't used this activation method but I suspect that it starts a program without providing either a UI or an output console. Is it reasonable that the program starts and runs but does not create any detectable output? Perhaps put a MessageBox() call in the startup sequence of your app...

If that isn't helpful, I don't have any further expertise with this way of activating; I haven't used this method.
Manel1989 11-Sep-13 23:06pm    
ok , thank You :)
now i use this it works when i use simple code not a GUI ok :
Runtime runtime = Runtime.getRuntime();

Process process2 = runtime.exec(new String[]{"C:\\Program Files\\Microsoft Visual Studio 10.0\\Common7\\IDE\\VCExpress.exe", "readxmlresou.exe"}, null, new File("C:\\Users\\abdelhalim\\Desktop\\"));

Now , when i put this code in a JButton code , it shows me this error : Unhandled exception type IOexception
So i tryed to added throws IOException in this code :
public void actionPerformed(ActionEvent arg0) throws IOException {
btnGecodeSolvePerformed(arg0);
}
but it tells me this :
Multiple markers at this line
- Exception IOException is not compatible with throws clause in
ActionListener.actionPerformed(ActionEvent)
- implements java.awt.event.ActionListener.actionPerformed

So, D you know any thing about that ????i think it is possible to start another application using a button isn't ????

Thank you again for your help :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900