0

I have a c++ program (.exe) that runs in the command line. You don't open it with cmd, it just opens the command prompt on its own and uses it as a menu. I also have a login system built in Java. My issue is, I'm trying to open my C++ program in the Java program, and it just isn't working. Here is the latest iteration of the relevant code:

    btnLaunchMyProgram.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            File file1 = new File("C://Users//" + System.getProperty("user.name") + "//Desktop//My Program//myprogram.exe");
            if(!file1.exists()) {
            try {
                HttpDownloadUtility.downloadFile("https://www.example.com/downloads/MyProgram.exe", "C://Users//" + System.getProperty("user.name") + "//Desktop//My Program//");
            } catch (IOException e) {
                e.printStackTrace();
            }
            }
            try {
                Process p = Runtime.getRuntime().exec(new String[] {"cmd.exe", "\"" + "C://Users//" + System.getProperty("user.name") + "//Desktop//My Program//MyProgram.exe" + "\""});
            } catch (IOException e) {

                e.printStackTrace();

            }

        }


    });

In order to get rid of a few concerns you might have - I have also tried the following, which runs my program in the background, but doesn't open the command prompt:

    Process p = Runtime.getRuntime().exec(new String[] {"C://Users//" + System.getProperty("user.name") + "//Desktop//My Program//MyProgram.exe"});

and also:

    Process p = Runtime.getRuntime().exec(new String[] {"cmd.exe", "C://Users//" + System.getProperty("user.name") + "//Desktop//My Program//MyProgram.exe"});

None of these work. Just to be clear about what I need to happen: 1. I press the button (btnLaunchMyProgram) 2. It opens the exe and, by extension, the command prompt / console. 3. That's basically all it needs to do.

Killzone Kid
  • 6,171
  • 3
  • 17
  • 37

0 Answers0